zeezack Posted February 14, 2008 Share Posted February 14, 2008 I have been asked to write some code that will extract details from a list. Using regular expressions in PHP I am trying to grab the NAME, NUMBER and the DESCRIPTION. I have got the number - but getting just the name and the description is eluding me. <tr valign="top"> <td nowrap> <big>1439</big> </td> <td nowrap>Amy</td> <td>Hi Guys Amy here. Raven haired lady with an electric personality and great sense of fun.</td> <td nowrap><span style="color:#333">Unavailable</span></td> <td nowrap><img src="images/lips.png" border="0" alt="No Recording Available"></td> </tr> How do I get the sentence ... "Hi Guys Amy here" and the name Amy here is the site I am working from - http://www.livebite.co.uk/includes/ukcoldajax.php and here is my current code the html is the source of that page ??? ??? $regex = "/(<td>[A-Za-z]*.*<\/td>)/"; if (preg_match_all($regex, $html, $match6)) { $i=0; foreach($match6[0] as $descriptions) { //$contents = htmlentities($descriptions); //change descriptions $pinvalue = $pinarray[$i]; echo ''.$i.'.'.$descriptions.'<br/>'; $i++; } } Quote Link to comment Share on other sites More sharing options...
effigy Posted February 14, 2008 Share Posted February 14, 2008 <pre> <?php $data = <<<DATA <tr valign="top"> <td nowrap> <big>1439</big> </td> <td nowrap>Amy</td> <td>Hi Guys Amy here. Raven haired lady with an electric personality and great sense of fun.</td> <td nowrap><span style="color:#333">Unavailable</span></td> <td nowrap><img src="images/lips.png" border="0" alt="No Recording Available"></td> </tr> DATA; ### Number. preg_match('%(?<=<big>)\d+(?=</big)%', $data, $matches); print_r($matches); ### Name. preg_match('%(?<=<td nowrap>)[a-z\s]+(?=</td>)%i', $data, $matches); print_r($matches); ### Desc. preg_match('%(?<=<td>).+?(?=</td)%', $data, $matches); print_r($matches); ?> </pre> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.