Thursday, 3 October 2013

parsing inline variables from string from file in php

parsing inline variables from string from file in php

I'm localizing a website that I've built. I'm doing this by having a .lang
file read and each line (syntax: key=string) is placed in a variable
depending on the chosen language.
This array is then used to place the strings in the correct places.
The problem I'm having is that certain strings need to have hyperlinks in
the middle of them for example someplace I've put my name that links to my
contact page. Or a lot of the readouts of the website need to be in the
strings.
To solve this I've defined a variable that holds the Forecaster and the
localization file contains the $Forecaster variable for the strings that
need tags.
The problem with this as I promptly discovered is that it stubbornly
refuses to parse the inline variables in the strings from the file.
Instead it prints the string and variable name as it looks in the file.
And I have yet to find a way to make it parse the variables.
For example "Heating up took $str_time" would be printed on the page
exactly like that, instead of inputting the previously defined value of
$str_time.
I currently use fopen() and fgets() to open and read the lines. I then
explode them to separate the key and the string and then place these into
the array.
Is there a way to make it parse the variables, or alternatively is there
another way of reading the lines that allows for parsing the inline
variables?

No comments:

Post a Comment