I want to delete <?xml version="1.0" encoding="utf-8"?>
from my string containg this and after that lots of other things. How to delete it because of several double quotes I am having problem to define str_replace
function.
Asked
Active
Viewed 141 times
-1

Brian Tompsett - 汤莱恩
- 5,753
- 72
- 57
- 129

Stefke
- 141
- 8
- 19
-
4[What have you tried?](http://www.whathaveyoutried.com/) See [ask advice](http://stackoverflow.com/questions/ask-advice), please. – John Conde Mar 23 '13 at 15:51
-
I tried str_replace("", '', $myString); dont know why you gave mi minus – Stefke Mar 23 '13 at 16:01
4 Answers
1
Just use single quotes then with str_replace :
$yourstring = str_replace('<?xml version="1.0" encoding="utf-8"?>', '', $yourstring);

Nelson
- 49,283
- 8
- 68
- 81
1
You could consider using single quotes:
str_replace('<?xml version="1.0" encoding="utf-8"?>', '', $myString);

juco
- 6,331
- 3
- 25
- 42
1
If you want to use double quotes to define the string then you need to escape them with \
:
str_replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "", $myString);
// ^ ^ ^ ^

h2ooooooo
- 39,111
- 8
- 68
- 102
0
Here is the solution:
<?php
$xml = '<?xml version="1.0" encoding="utf-8"?>
<parentnode>
<childnode>
Hello World!
</childnode>
</parentnode>';
$xml_to_delete = '<?xml version="1.0" encoding="utf-8"?>';
$new_xml = str_replace($xml_to_delete, "", $xml);
echo $new_xml; //Raw XML.
echo "<br/>";
echo htmlentities($new_xml); //For seeing output in browsers, instead of XML rendered.

sp2012
- 133
- 8