Splitting output Newbie

Discussion in 'PHP' started by webboy, Aug 20, 2008.

  1. #1
    Hi all
    I wish to extract some content from an html file then output the data in two strings for a database.

    I have managed to extract the data using a regular expression and the html file looks like following.

    <font color='#660000'>Handbags</font></b>
    <font color='#660000'>Muppets</font></b>
    <font color='#660000'>Yellow fish</font></b>
    <font color='#660000'>Fog Green</font></b>


    I used preg_match extract the data

    preg_match_all('/<font color=\"(.*)\">(.*)<\/font>/', $input, $matches);

    I wish to have an output of

    Handbags, Muppets (field 1 , field 2)
    Yellow fish, Fog Green (field 1 , field 2)

    And not one whole string Handbags Muppets Yellow fish Fog Green

    Do I have to create a loop for every two arrays matches to split it
    what would the code be
     
    webboy, Aug 20, 2008 IP
  2. Freewebspace

    Freewebspace Notable Member

    Messages:
    6,213
    Likes Received:
    370
    Best Answers:
    0
    Trophy Points:
    275
    #2
    This would help you..

     
    Freewebspace, Aug 20, 2008 IP
  3. webboy

    webboy Peon

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the reply
    I made a small mistake on the data as i should read

    <font color="#0000BB">Muppet</font></a></td>
    <td align="left">Tinbox man</td>
    <td class="fish"><div>Ginger bread</div></td>

    preg_match_all('/<font color=\"\#0000bb\">(.*)<\/font>/', $input, $matches);
    preg_match_all('/<td align=\"left(.*)\"><\/td>/', $input, $person);
    preg_match_all('/<div>(.*)\">(.*)<\/div>/' ,input, $body);

    now i did the preg_match and wish to see the ouptut as filed 1, filed 2,filed 3

    also could i get the output even no match happens to keep it consistent
     
    webboy, Aug 20, 2008 IP