PREG Issue

Discussion in 'PHP' started by asgsoft, Oct 24, 2007.

  1. #1
    Hi

    I've been trying to understnad preg for a while now and don't know where I am going wrong with this:

    <?php
    function getweb($website)
    {
       if(!$ch = curl_init($website)) {
        echo "Could not connect to $website";
           return;
       }
       curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt ($ch, CURLOPT_HEADER, 0);
       $output = curl_exec($ch);
       curl_close ($ch);
       return $output;
    }
    
    $total = getweb('http://www.thewebmasterstool.com/'); 
        $match_expression = '/<title>(.*?)\/<\/title>/i';
        preg_match($match_expression,$total,$matches); 
    $asd =  strip_tags($matches[1]);
    echo $asd;
    ?> 
    PHP:
    Thanks
     
    asgsoft, Oct 24, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Remove this between the <title> tags: \/

    This would match a forward slash followed by the </title> tag, which is most likely causing the error.

    Other than that, it works.
     
    nico_swd, Oct 24, 2007 IP
  3. asgsoft

    asgsoft Well-Known Member

    Messages:
    1,737
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Thanks, that works fine.
     
    asgsoft, Oct 24, 2007 IP