Jump to content

[resolved] str_replace special characters


rvdokkum

Recommended Posts

i like to use the str_replace to change the header of xml dataoriginal xml data:<?xml version="1.0" encoding="UTF-8"?><tumblr version="1.0"><tumblelog .........i like to replace :<?xml version="1.0" encoding="UTF-8"?>with<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="xsl_template_document"?>how do i handle the special characters in these strings?i try to implement this example. therefore i need to change the header of my xml data to point to my stylesheet xsl file.http://modxcms.com/forums/index.php/topic,....html#msg127144

Link to comment
Share on other sites

When using function, try with str_replace('something', 'something "else"', $string);So use single quotes for arguments.If it won't work use then version=\"1.0\" etc.

Link to comment
Share on other sites

When using function, try with str_replace('something', 'something "else"', $string);So use single quotes for arguments.If it won't work use then version=\"1.0\" etc.
give it a trystill can't get it to work
Link to comment
Share on other sites

You can either replace the tags with string functions, or you can use PHP's DOMDocument class.Replacing the strings is easy:

$result = str_ireplace('<?xml version="1.0" encoding="UTF-8"?>','<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="xsl_template_document"?>',$xmlString);

The only problem with it is that if you have extra spaces it won't be detected.If you use PHP's DOMDocument class you can use createProcessingInstruction() and insertBefore() to add the stylesheet.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...