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?

Thanks!

Recommended Answers

All 4 Replies

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.