NameSilo

PREG Issue

Spaceship Spaceship
Watch

asgsoft

VIP Member
Impact
9
Hi

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

PHP:
<?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;
?>

Thanks
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
That site didn't even load in Firefox for me...

But here's my go, with my own get_page

PHP:
  <?php

function get_page($url, $timeout="", $ref="", $user="")
  {   
  /* This function grabs the content of a page using cURL if it's available, or file_get_contents if it's not.
  Example usage: echo get_contents("http://www.google.com","IE7 MSIE","",5); */
   if (!function_exists('curl_init') or !function_exists('curl_exec')) { 
    return file_get_contents($url);
    } else {    
    if (!$timeout or $timeout == 0) { $timeout = 10; /* No infinite pages please */ }
    if (!$user) { $user = "Microsoft Internet Exploder"; }
    if (!$ref) { $ref = "http://www.google.com/search?q=".rand(0,1000)."+facts&ie=utf-8&oe=utf-8"; }
    $ch = curl_init();  
    curl_setopt($ch, CURLOPT_URL, $url);    
    curl_setopt($ch, CURLOPT_REFERER, $ref);    
    curl_setopt($ch, CURLOPT_USERAGENT, $user);        
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);    
    $output = curl_exec($ch);    
    curl_close($ch);    
    return $output;   
  } } 

$total = get_page("http://danltn.com/",60); 
$match_expression = '/<title>(.*)<\/title>/';
preg_match($match_expression,$total,$matches); 
$tag = $matches[1];
echo $tag;

?>
 
Last edited:
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back