Results 1 to 4 of 4

Thread: Regex Query

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

    Default Regex Query

    I have this very useful following code

    Code:
    <?php
    
    $url = 'http://www.cheapsmells.com/viewProduct.php?id=3978';
    
    $parts = array ( array ( '<div class=\'productOriginalPrice\'>', '</div>' ), array ( '<div class=\'productOurPrice\'>', '</div>' ) );
    
    $out = array ( 'original' => '', 'current' => '' );
    
    if ( false !== ( $page = file_get_contents ( $url ) ) )
    {
    	foreach ( $parts AS $name => $value )
    	{
    		if ( false !== ( $s = stripos ( $page, $value[0] ) ) )
    		{
    			$page = substr ( $page, $s + strlen ( $value[0] ) );
    
    			$out[($name == 0 ? 'original' : 'current' )] = preg_replace ( '/(.+?)(\d+\.\d+)(.+?)?/is', '\\2', substr ( $page, 0, strpos ( $page, $value[1] ) ) );
    		}
    	}
    }
    
    print_r ( $out );
    
    ?>
    What I need to do is have $out or another similar variable define just "22.54" without returning "Array ( [original] => 36.00 [current] => 22.54 )" which it does at the moment.

    The original price is of no relevance and I don't need it really, I just need the current price defined so i can use UPDATE with mySQL.

    many thanks in advance and a HAPPY NEW YEAR!

  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    PHP Code:
    print_r $out['current'] ); 
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    $out = $out['current'];
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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

    Default

    thank you very much.

    one question. how would i now change this to co-ordinate with

    Code:
    $url = 'http://www.adonisgrooming.com/product.php?productid=6947&cat=1363&page=1'
    i have tinkered with it and can't get it to work. the only difference being that the tags for this code only return "£xx.xx" as opposed to "Our Price £xx.xx"

    many thanks again

    oh, plus this is the parameter tags
    Code:
    <SPAN id="product_price">£35.25
    </SPAN>
    i'm at a bit of a loss as to how to change this code to just get the current price. the original price is kinda useless to me but every time i try to touch the code i wreck it. lol.

    anyways, happy new year and yee-hah!
    Last edited by halifaxer; 01-02-2008 at 01:05 AM.

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
  •