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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.