0

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
  • The XML seems to be incorrectly formed... Do you have the possibility to fix that and have directly & instead of & in the XML ? Since doing a str_replace when fetching the (maybe) malformed XML wouldn't resolve the original problem... Commented Oct 28, 2010 at 8:27

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

3 Comments

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.
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.
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!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.