All pastes #885010 Raw Edit

Anonymous

public php v1 · immutable
#885010 ·published 2008-01-30 18:48 UTC
rendered paste body
<?phpclass parser{var $nofollow = array(    "google.com",    "microsoft.com",    "live.com",    "msn.com"  );  // Hauptfunktionfunction hyperlink($text) {    $text = ' '.$text.' ';        // match protocol://address/path/file.extension?some=variable&another=asf%    // allow hit \s also start and end!    $text = preg_replace_callback("/\s([a-zA-Z]+:\/\/[a-z][a-z0-9\_\.\-]*[a-z]{2,6}(\/[a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)?)([\s|\.|\,])/i",            array('self', 'my_http'), $text);                // match www.something.domain/path/file.extension?some=variable&another=asf%    $text = preg_replace_callback("/\s(www\.[a-z][a-z0-9\_\.\-]*[a-z]{2,6}(\/[a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)?)([\s|\.|\,])/i",            array('self', 'my_www'), $text);                // match name@address    $text = preg_replace("/\s([a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]*\@[a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]{2,6})([\s|\.|\,])/i",            " <a href=\"mailto://$1\">$1</a>$2", $text);                return substr($text, 1, -1);}// callback Funktionfunction my_http($data) {         $domain = $this->getdomain($data[1]);  $rel = (in_array(strtolower($domain), $this->nofollow)) ? "rel=\"nofollow\"" : "rel=\"follow\"";    return " <a href=\"$data[1]\" target=\"_blank\" $rel>$data[1]</a>$data[3] ";}//callback Funktionfunction my_www($data) {  $domain = $this->getdomain($data[1]);  $rel = (in_array(strtolower($domain), $this->nofollow)) ? "rel=\"nofollow\"" : "rel=\"follow\"";    return " <a href=\"http://$data[1]\" target=\"_blank\" $rel>$data[1]</a>$data[3]";}// http://www.namepros.com/53456-parse-a-url-php-return-domain-2.htmlfunction getdomain($url) {  $url = strtolower($url);  $slds =     '\.co\.uk|\.me\.uk|\.net\.uk|\.org\.uk|\.sch\.uk|    \.ac\.uk|\.gov\.uk|\.nhs\.uk|\.police\.uk|    \.mod\.uk|\.asn\.au|\.com\.au|\.net\.au|\.id\.au|    \.org\.au|\.edu\.au|\.gov\.au|\.csiro\.au';    preg_match ("/^(http:\/\/|https:\/\/|ftp:\/\/|)([^\/]+)/i",$url, $matches);    $host = $matches[2];    if (preg_match("/$slds$/", $host, $matches)) {        preg_match ("/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/", $host, $matches);    }     else {        preg_match ("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);    }    return "{$matches[0]}";}  }// END - Class?>