SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    933
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Arrow pregmatch() question?

    I have these codes below,

    Code:
    <?php
    //include methods/class
    include_once 'simple_html_dom.php';
    include_once 'casting.inc.php';
    
    
    // Create DOM from URL
    $url = "http://sampledomain.org/tlg/";
    $html = file_get_html($url);
    
    // Find all links
    // connect exact url and make it live link
    foreach($html->find('a') as $element) {
    	#echo "<b>" . $element->href . "</b><br>"; 
    	
    	//check if href has /html/ if yes then connect right live url
    	if(preg_match("/tlg/", $element->href)) {
    		if(preg_match("/html/", $element->href)) {
    			$atlanta_url['url'] = $element->href;
    			echo $atlanta_url['url'] ."<br>";
    		}
    	}
    
    }
    
    		 
    ?>
    The result of that codes you will see below,
    http://czone01.com/onstaged/scrape_craig_old.php

    I don't understand why these strings below, still included?
    rose1.2515
    daisy0.7525
    orchid1.157

    It suppose to be excluded since the pregmatch() should limit that.

    Anybody would like to help me figure that out please?

    Is this a pregmatch() flaw?

    Thanks in advance.
    Last edited by solidcodes; May 25, 2009 at 20:30. Reason: typographical error.

  2. #2
    messing with my mind fristi's Avatar
    Join Date
    Feb 2009
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see the faulty urls you speak of in the script you provided...

    But if you are only searching for simple strings and no complex expressions I would recommend the use of strpos instead of preg_match. it is faster.

    http://en.php.net/function.strpos
    To PHP or to Perl, that is the question!
    (Bucket - simpletest) User

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    See my post here.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


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
  •