homepage Welcome to WebmasterWorld Guest from 50.17.177.99
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
preg match all value between two tags and loop
ahmed24




msg:4036957
 2:21 pm on Dec 4, 2009 (gmt 0)

I have a variable called $content that looks like this:

$content = '<td class="data2">1st Information</td><td class="data2">2nd Information</td><td class="data2">3rd Information</td>';

i want to be able to get the information between the <td class="data2"> and the </td> tag and loop it.

So for example once it is done, instead of having the following:

<td class="data2">1st Information</td>
<td class="data2">2nd Information</td>
<td class="data2">3rd Information</td>

It should be the following:

1st Information<br>
2nd Information<br>
3rd Information<br>

Can anyone please help?

Thanks

 

NomikOS




msg:4036994
 3:28 pm on Dec 4, 2009 (gmt 0)

$content = '<td class="data2">1st Information</td><td class="data2">2nd Information</td><td class="data2">3rd Information</td>'; 
$store = array();

if (preg_match_all("/<td class=\"data2\">(.*?)<\/td>/si", $content, $aux))
{
$store[] = $aux[0];
}

var_dump($store);

[edited by: NomikOS at 3:34 pm (utc) on Dec. 4, 2009]

NomikOS




msg:4036995
 3:29 pm on Dec 4, 2009 (gmt 0)

# to isolate each data cell use PREG_SET_ORDER flag: 

if (preg_match_all("/<td class=\"data2\">(.*?)<\/td><td class=\"data2\">(.*?)<\/td><td class=\"data2\">(.*?)<\/td>/si", $content, $aux, PREG_SET_ORDER))
{
foreach ($aux as $aux2)
{
$store['1st Information'][] = $aux2[1];
$store['2st Information'][] = $aux2[2];
$store['3st Information'][] = $aux2[3];
}
}


Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved