2

I tryed to grab the price from the html source here is the part of the source

 <h1>
    <span id="ctl00_PageHeaderContentPlaceHolder_lblRegion">Product Name</span>
    <strong id="ctl00_PageHeaderContentPlaceHolder_divFiyat" class="price">
        749 €
        <small>
            2007 TL
            <small class="nightday">
                <span id="ctl00_PageHeaderContentPlaceHolder_lblNightDay">Un related detals</span></small></small>
    </strong>
</h1>

As you see here it is very specified id. Here is my code..

 $Tour_Price ="/<span id=\"ctl00_PageHeaderContentPlaceHolder_divFiyat\" class=\"price\">(.*?)<\/span>/i";
        preg_match($Tour_Price , $Tur_Fiyat, $Result_Price);
        echo "<strong>Result:</strong>".$Result_Price[1];

My code works perfectly in other parts of the source. But price only doesnt. Please shoot ideas. Thanks to all interested :)

BKadmin
  • 39
  • 7
  • 6
    Why `preg_match`? Are you aware of `DOMDocument`: http://php.net/manual/en/class.domdocument.php ? – Alma Do Aug 23 '13 at 11:36
  • That markup looks horrible. Is that SharePoint? – Madara's Ghost Aug 23 '13 at 11:37
  • You have no: ctl00_PageHeaderContentPlaceHolder_divFiyat with that span id. check th eid's. – Jonathan Römer Aug 23 '13 at 11:37
  • JonatanRomer, I do copy/paste but not working still. – BKadmin Aug 23 '13 at 11:49
  • **Don't use regular expressions to parse HTML. Use a proper HTML parsing module.** You cannot reliably parse HTML with regular expressions, and you will face sorrow and frustration down the road. As soon as the HTML changes from your expectations, your code will be broken. See http://htmlparsing.com/php for examples of how to properly parse HTML with PHP modules that have already been written, tested and debugged. – Andy Lester Aug 23 '13 at 12:49

2 Answers2

0

You specify <span instead of <strong at the beginning of your regex.

But in your source span and strong have different ids.

Mundi
  • 79,884
  • 17
  • 117
  • 140
0

Try with this Code:

$Tour_Price ="/<strong id=\"ctl00_PageHeaderContentPlaceHolder_divFiyat\" class=\"price\">(.*?)<\/strong>/is";
preg_match($Tour_Price , $Tur_Fiyat, $Result_Price);
echo "<strong>Result:</strong>".$Result_Price[1];

Notic: The changes are span to strong and {...}/i to {...}/is

mordilion
  • 33
  • 1