Jump to content

Extract Certain Values from HTML Code


skitchen

Recommended Posts

Hi there

 

I've been trying to figure out a way of doing this using various options but with little success.

 

I have the html output of a full webpage and I have no control over how the webpage is output and I am using the file_get_contents() function to retrieve it. I only need to extract two pieces of information from the results page.

 

This is the the section of the code with the information that I need to "extract" in bold.

 

<em> Your reference number is [b]XYZ321[/b].</em>
</h2>

<p class="subtitle"><em>
Your voucher is valid until [b]30 September 2009[/b].</em></p>

 

Can anybody provide any help as to how to retrieve just the reference number and the expiry date?

 

Thanks very much

Steve

Link to comment
Share on other sites

You could try this (there may be a better way):

 

$input = '<em> Your reference number is XYZ321.</em>
</h2>

<p class="subtitle"><em>
Your voucher is valid until 30 September 2009.</em></p>';

if(preg_match("~is (.+?).~",$input,$matches)){
     print_r($matches);
}else{
     echo 'no matches';
}

if(preg_match("~until (.+?).~",$input,$matches)){
     print_r($matches);
}else{
     echo 'no matches';
}

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.