Results 1 to 2 of 2

Thread: Regex Script Help

  1. #1
    Join Date
    Aug 2007
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Regex Script Help

    I think I did post this some time ago, but can't find original thread to rehash. I have some questions regarding lifting data from a particular webpage. What makes this unusual and why I need to ask some questions is that within the tags, there is a lot of white space and the data doesn't actually sit within closed tags eg. <span>data</span>, it falls like this

    Code:
                                            <td width="55%"><div class="value">
                                                &pound;6.99 <font size="3"> </font></div>
    										    
                                            </td>
    With the "&pound;6.99" being what I want to extract and use. for example, this code works perfectly for a different website.

    Code:
    $url = 'http://www.cheapsmells.com/viewProduct.php?id=3462';
    $html = file_get_contents($url);
    
    preg_match('/<div class=\'productOurPrice\'?>(.+?)(\d+\.\d+)(.+?)?<\/div>/', $html, $match);
    $out = $match[2];
    Where the url is http://www.directcosmetics.com/resul...mer&code=34744 which is where the first example where the whitespace is, how can I adjust the above regex to obtain the information required, in this case literally "6.99" and nothing more. Is it possible because it's not within closed brackets?

    Any help you can shed my way wouldbe greatly apprecviated.

    Cheers ;D

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Let me know if this works:
    Code:
    $url = 'http://www.directcosmetics.com/results/products.cfm?ctype=ME&range=Hummer&code=34744';
    $html = file_get_contents($url);
    preg_match('/<div class=\"value\"?>(.+?)(\d+\.\d+)(.+?)?<\/div>/s', $html, $match);
    $out = $match[2];
    echo "<textarea cols=144 rows=44>$out</textarea>";
    Notice the modifier I added on this line:
    Code:
    preg_match('/<div class=\"value\"?>(.+?)(\d+\.\d+)(.+?)?<\/div>/s', $html, $match);
    Last edited by james438; 02-07-2008 at 04:31 AM. Reason: spelling error

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •