Jump to content

ASAP please help - REGULAR expression


zeezack

Recommended Posts

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++;

}

}

Link to comment
https://forums.phpfreaks.com/topic/91064-asap-please-help-regular-expression/
Share on other sites

<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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.