Jump to content

[SOLVED] help with preg_match


tomasd

Recommended Posts

Thanks very much for your reply, your solution works fine when

$data = "<FONT class=price>239.00 GBP</FONT>";

however my $data is much more than "<FONT class=price>239.00 GBP</FONT>", as a matter of fact I have whole html output for a page, is there any of extracting the price from it at all?

 

cheers!

I'm using following code:

$output = curl_exec ($ch);
if (preg_match('%<Font\\sclass=price>([0-9\\.]+\\s+\\w+)\\<\\/Font>%i', $output, $regs)) {
        $price = $regs[0];
        } else {
                $price = "failed\n";
                }
                echo $price;

 

after running the file:

[tomas@dummy curl]$ php -f curl.php

failed

 

If I simply echo $output and grep for <FONT class=price> I'm getting what I'm supposed to...

Hi, I still have no luck :(

Here's the full code I'm using:

<?php
$ch = curl_init();
$today = date("Ymd");
$date = $today + 101;

curl_setopt($ch, CURLOPT_URL, "http://www.bookryanair.com/skylights/cgi-bin/skylights.cgi");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,"travel_type=on&sector1_o=STN&sector1_d=MJV&ADULT=1&nom=1
&date1=$date&date2=''&page=SELECTED");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec ($ch);

if (preg_match('%<Font\sclass=price>([0-9\.]+\s+\w+)\<\/Font>%i', $data, $regs)) {
  $price = $regs[0];
  } else {
    $price = "";
    }
    echo $price;

curl_close ($ch);
?>

ahh

 

 

ok you missed the '

 

heres an example that should help

 

<?php
if (preg_match("%<Font\sclass='price'>([0-9\.]+\s+\w+)\<\/Font>%i", $data, $regs)) {
$price = $regs[0];
} else {
$price = "";
}
echo "FIRST: $price<br />";

preg_match_all("%<Font\sclass='price'>([0-9\.]+\s+\w+)\<\/Font>%i", $data, $result, PREG_PATTERN_ORDER);
$result = $result[0];

echo "and the rest:<br />";
foreach($result as $price)
{
echo "$price<br />";
}
?>

you are the best!

[tomas@dummy tomas]$ php -f curl.php
FIRST: <font class='price'>34.99 GBP</font><br />and the rest:<br /><font class='price'>34.99 GBP</font><br /><font class='price'>34.99 GBP</font><br />[tomas@dummy tomas]$

 

Thanks ever so much for your help and patience!!!

 

p.s. my holidays to spain Shall become more often :)

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.