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
https://forums.phpfreaks.com/topic/133074-extract-certain-values-from-html-code/
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';
}

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.