I have an XML file which im fetching using php . That file contains '&' which gives error while fetching the file. Now i want to replace this "&" from my XML.How can i do that using php???
1 Answer
The simplest way is with string replace:
str_replace("&", "&", $xml_str);
http://php.net/manual/en/function.str-replace.php
Have in mind that if you have "&" in the xml they will become "&" So you can try:
str_replace("&", "&", $xml_str);
str_replace("&", "&", $xml_str);
3 Comments
developer
this thing will work when i'll be able to read xml file.Since my xml file is giving error on retrieval i need a code that can replace the text in the file in one go without retrieving it.
Ilian Iliev
Do not parse the XML. Just read it as text and replace it. If you can not read it from specific file/url than this is other problem.
developer
problem is solved now.We were taking data from another server and file was giving an error while even opening it on URL.So we asked them to make the file properly and now its running fine.Thanks!!
&instead of&in the XML ? Since doing astr_replacewhen fetching the (maybe) malformed XML wouldn't resolve the original problem...