We have a server that has PHP 4.4.8 on it so SimpleXML is not an option.

I have a curl response string ($curl_response) that is virtually the same every time. I need to extract the PhnNbr, DNC, Filter, and Flag fields to 4 separate strings.

Here is what the XML looks like.

<string xmlns="http://www.xxxxxxxx.com/">
<PhnNbr><Number>9999999999</Number><DNC>1</DNC><Filter>Wireless</Filter><Flag>WIR</Flag></PhnNbr></string>

Any thoughts??

Thanks
Steve

    upgrade, php 4.4.8 is dangerously out of date, no security patches will be issued for it

    Support for PHP 4 has been discontinued since 2007-12-31. Please consider upgrading to PHP 5.

      I wish... But I do not have control of the server. Big company and I am way down on the totem pole. I have to make due with what I have.

        tell them they are asking to be 'hacked', however you could do it with regular expressions or DOM XML

          I actually got them to update this morning. So I can now use simplexml. But I have a new problem I have not come across. If you look at my sample xml above, the entire document is coming in as a <string> data type.

          What would you use as the quickest way to convert it back so simplexml will work?

          Thanks

            fotofx;10957526 wrote:

            What would you use as the quickest way to convert it back so simplexml will work?

            back to what? an xml file is a string.

              <?php
              
              $xmlstr='
              <string xmlns="http://www.xxxxxxxx.com/">
              <PhnNbr><Number>9999999999</Number><DNC>1</DNC><Filter>Wireless</Filter><Flag>WIR</Flag></PhnNbr></string>';
              
              $xml = new SimpleXMLElement($xmlstr);
              
              print_r($xml);
              
              
              ?>

              SimpleXMLElement Object
              (
              [PhnNbr] => SimpleXMLElement Object
              (
              [Number] => 9999999999
              [DNC] => 1
              [Filter] => Wireless
              [Flag] => WIR
              )

              )

                Hmmm... Why am I not getting the same result????

                I am taking the original XML from a curl response. Must be something in there I am missing..

                  Works fine using your example but if I use

                  $curl_result_d=curl_exec($ch);
                  $xmlstr=$curl_result_d;
                  

                  It returns:

                  SimpleXMLElement Object ( [0] => 99999999991WirelessWIR )

                    Just noticed, the actual response is urlencoded.. Looks more like this:

                    snip.....com/">&lt;PhnNbr&gt;&lt;Number&gt;....snip
                    

                    Wonder if that is part of the problem?

                      Tried

                      $xmlstr= urldecode($curl_result_d);
                      

                      And that didn't work.. Looking at the source it still looks encoded?????

                        Here is the actual full curl_response with only minor editing..

                        <?xml version="1.0" encoding="utf-8"?>
                        <string xmlns="http://www.xxxxxxxx.com/">&lt;PhnNbr&gt;&lt;Number&gt;9549999999&lt;/Number&gt;&lt;DNC&gt;1&lt;/DNC&gt;&lt;Filter&gt;FLORIDA 954,Florida,Wireless&lt;/Filter&gt;&lt;Flag&gt;NFL,FL1,WIR&lt;/Flag&gt;&lt;/PhnNbr&gt;</string>
                        

                          Think I got it..

                          $xmlstr= html_entity_decode($curl_result_d);
                          

                            Thanks for the help... Sometimes it just takes someone else looking at it to give you a new perspective. Your example made all the difference because I just had to figure out what was different. I documented my efforts above, as I went in case someone else comes across a similar problem.

                            Thanks again,
                            Steve

                              Write a Reply...