First, I'm pulling text from one XML file which is just a name and putting it in a $name variable.
Then I'm pulling some other text from a different XML file and this text contains a variable, let's say:
<list>
<wishes>
<id>001</id>
<text>Happy birthday, '.$name.'</text>
</wishes>
</list>
As you see, I already tried to format it in a way which should conc... conat... parse it, but it doesn't. Once I include it in something as simple as this:
foreach ($people->user as $person) {
if ($person->date == date('d.m')) {
$name = $person->name;
foreach ($list->wishes as $wish) {
$text = $wish->text;
}
echo 'Wishes for '.$name.'.';
echo 'Wish example: '.$text.' something something';
}
The result will be:
Wishes for John.
Wish example: Happy birthday, '.$name.' something something
It will treat the variable as plain text instead of replacing it with the actual name of the person.
So how do I force it to replace the $name variable with the actual name if the variable is contained in an XML file? BTW, I also tried to include echo or print in various places - inside the XML file, by setting another variable that would print the content of the XML file and then set that variable as the one that's echoed in the end - no luck, it just keeps treating it as text.
$wish->text = str_replace('$name',$person->name,$wish->text)be enough? I feel allowing arbitary variable replacement or even using eval could open up your code to explotation. Where does the original text come from anyway?