Ok, probably quite a basic question, but here goes:

I'm creating a string that will hold the contents of an xml file that is being created dynamically.

here's an example:
$new_xml = "<?xml version='1.0'?>-<params>-<param><key>$clubName</key><textValue>" .$club_name;

Having looked at this, I've suddenly realised that the string part is still going to look for a variable becuase it has a leading $

How do I distinguish between the green highlight which is a pure string value that contains a $ and the red highlight which is actually calling a variable?


5 Years
Discussion Span
Last Post by spanners

I am not sure if I understood the question but if you do not want to get the green $clubName parsed and replaced with it's value either escape the $ like \$clubName or put the whole string in single quotes and xml attributes in double quotes like:

$new_xml = '<?xml version="1.0"?>-<params>-<param><key>$clubName</key><textValue>' .$club_name;

that does seem to work for preventing the $ parsing the value - but it appears to knock out all the xml?!

$new_xml = '<?xml version="1.0"?>-<params>-<param><key>$clubName</key><textValue>' .$club_name;

Outputs: --$clubNamemy test club

When I was hoping for: <?xml version="1.0"?>-<params>-<param><key>$clubName</key><textValue>my test club


Does the version with double quotes and escaped $ give expected result?

$new_xml = "<?xml version='1.0'?>-<params>-<param><key>\$clubName</key><textValue>" .$club_name;

Please specify what is the expected result.


No, bu when I write it to a text file it works! Which is fine as ultimately that's what I'm trying to do - not outputting to the screen just means testing is a bit long winded, but I can deal with that!

Thanks for your help :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.