#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    26
    Rep Power
    0

    Parsing cURL return


    Hello ladies and gentlemen. This is my first post to this forum. I am learning PHP right now and as of today, I am terrible at it. I am brand new. I am familiar with another proprietary language called netlinx, which is somewhat similar in many ways, but the string manipulation and all is totally different.

    At any rate, I am working on a project where I will ultimately populate a database with all sorts of product data for the backend of an ecommerce site, but I am in the process right now of simply figuring out how PHP works. The manual and examples are great, if you sort of have a rough idea what you are looking for, but in this situation, I don't know really what direction to go in.

    I have some data that comes back in response to a cURL exec (see below). I don't know what to do to sort of categorize it. It is basically some category numbers, followed by a name and attribute. Eventually, I will try to cram this into a database table, but right now I am just trying to parse the data and don't know where to start. In the language I normally work with, there is a function called REMOVE_STRING (Variable,Delimiter,Start Position) and I would for loop through all this stuff. I have seen the EXPLODE function, but all the examples are very simple with single instances of single character delimiters. What direction do I need to go in to start cramming this into a multidimensional array, and then eventually into database tables? This is an example of basically how all the data will be setup....just different field tags when it turns to say, manufacturer, quantity on hand, etc...

    In this window it posts very structured, but as it come into the webpage, it looks like one crammed long string.

    DATA SAMPLE

    <NewDataSet>
    <Table>
    <CATID>0</CATID>
    <CATDES>UNASSIGNED </CATDES>
    <ATTR1>locked </ATTR1>
    <ATTR2 xml:space="preserve"> </ATTR2>
    <ATTR3 xml:space="preserve"> </ATTR3>
    <ATTR4 xml:space="preserve"> </ATTR4>
    <ATTR5 xml:space="preserve"> </ATTR5>
    <ATTR6 xml:space="preserve"> </ATTR6>
    <ATTR7 xml:space="preserve"> </ATTR7>
    <ATTR8 xml:space="preserve"> </ATTR8>
    <ATTR9 xml:space="preserve"> </ATTR9>
    <ATTR0 xml:space="preserve"> </ATTR0>
    </Table>
    <Table>
    <CATID>1</CATID>
    <CATDES>ACCESSORIES MISCELLANEOUS </CATDES>
    <ATTR1>Type </ATTR1>
    <ATTR2>Model or Style </ATTR2>
    <ATTR3>Color </ATTR3>
    <ATTR4>Size </ATTR4>
    <ATTR5>Material </ATTR5>
    <ATTR6>Gauge </ATTR6>
    <ATTR7>Mount </ATTR7>
    <ATTR8>Battery Config </ATTR8>
    <ATTR9>Height </ATTR9>
    <ATTR0>Model Fit </ATTR0>
    </Table>
    <Table>
    <CATID>2</CATID>
    <CATDES>AIR GUNS </CATDES>
    <ATTR1>Type </ATTR1>
    <ATTR2>Action </ATTR2>
    <ATTR3>Caliber </ATTR3>
    <ATTR4>Capacity </ATTR4>
    <ATTR5>Finish </ATTR5>
    <ATTR6>Barrel Length </ATTR6>
    <ATTR7>Sights </ATTR7>
    <ATTR8>Weight </ATTR8>
    <ATTR9>Stock </ATTR9>
    <ATTR0>Length </ATTR0>
    </Table>
    <Table>
    <CATID>3</CATID>
    <CATDES>ATV ACCESSORIES </CATDES>
    <ATTR1>Type </ATTR1>
    <ATTR2>Model </ATTR2>
    <ATTR3>Color </ATTR3>
    <ATTR4>Material </ATTR4>
    <ATTR5>Size </ATTR5>
    <ATTR6>Additional Info </ATTR6>
    <ATTR7>Hardware Included </ATTR7>
    <ATTR8>Vinyl Type </ATTR8>
    <ATTR9>Weight Capacity </ATTR9>
    <ATTR0>Hitch Type </ATTR0>
    </Table>
    <Table>
    <CATID>4</CATID>
    <CATDES>BLANK ROUNDS </CATDES>
    <ATTR1>Type </ATTR1>
    <ATTR2>Caliber
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    26
    Rep Power
    0
    FYI that data comes in from a URL not a file.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    26
    Rep Power
    0
    It appears SIMPLE XML functions are the key, but my variable


    $Check_Value is always a boolean; in an example video I found online, it comes in as a string...can't figure out why mine stays boolean.

    I really only want to populate a variable with the CURL_EXEC material, not output it to the browser. I just want it to fill with XML data....

    $ch = curl_init();

    $URL_VALUE="URL THAT WORKS BUT FORUM WONT ALLOW POSTING"

    curl_setopt($ch, CURLOPT_URL,$URL_VALUE );
    curl_setopt($ch, CURLOPT_HEADER, 0);



    $Check_Value=curl_exec($ch);


    curl_close($ch);
  6. #4
  7. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    cURL is sort of special in that the default value for CURLOPT_RETURNTRANSFER is retarded. In order to get useful output from curl_exec, change it to true:
    PHP Code:
    curl_setopt($chCURLOPT_RETURNTRANSFER1); 
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo