Hello. I am having a problem getting str_replace to replace some text in a string that I get from a remote XML file. One of the values in the XML file is for the firmware of a modem, and it contains "<<" and ">>" characters. So when I attempt to parse the XML with xml_parse_into_struct it sees those as incorrect tags and ignores them leaving them out of the document completely.
Here is an example of the string that is returned (before parsing the XML):
ARRIS DOCSIS 1.1 / PacketCable 1.0 Touchstone Telephony Modem <<HW_REV: 32; VENDOR: Arris Interactive, L.L.C.; BOOTR: 5.01; SW_REV: 4.4.28B; MODEL: TM402P>>
And it just so happens that all the information I need is between the << and >> tags.
So, I took the document, put it in a tmpfile() and sent each line ( using fgets() ) through str_replace but it doesn't even look like PHP is seeing the "<<" or ">>" at all, let alone replacing it. Here is the code I have. I have been struggling with this for days now and I think it's time to get some help lol.
Here is the code I have:
<?php
//XML URL
$url = "http://someurlthatputsoutXML.com";
//Open the url and a create a temp file for later use
$xml = fopen($url, "r");
$temp = tmpfile();
//Loop through the file looking for << or >> to remove
while (!feof($xml)) {
$my_string = trim(fgets($xml));
if ((strstr($my_string, "<<")) || (strstr($my_string, ">>"))) {
$find = Array("<<", ">>");
$replace = "";
$my_string = str_replace($find, $replace, $my_string);
//This will be replaced with a command to write the output to $temp as
//soon as I can get it to replace the string correctly.
echo $my_string . "<br><br>";
}
}
?>
This returns nothing because it isn't finding the << or >>. If I take out the "if" condition, it returns the same string that is input.
Thanks in advance for your help.
Keith
VoIP Engineer/Applications Developer for Cox Communications