Regular Expression

http://www.hvaonline.net/hvaonline/posts/list/20059.hva
http://www.nhatnghe.com/forum/showthread.php?t=67388
<?php
/* example usage :
$file = file_get_contents("http://www.yourwebsite.com&quot;);
$x = (get_link_rel($file));
print_r($x);
*/

// retrieve doctype of document
function get_doctype($file){
$h1tags = preg_match('//is’,$file,$patterns);
$res = array();
array_push($res,$patterns[0]);
array_push($res,count($patterns[0]));
return $res;
}

// retrieve page title
function get_doc_title($file){
$h1tags = preg_match(‘/ ?.* /isx’,$file,$patterns);
$res = array();
array_push($res,$patterns[0]);
array_push($res,count($patterns[0]));
return $res;
}

// retrieve keywords
function get_keywords($file){
$h1tags = preg_match(‘/()/i’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}

// get rel links in header of the site
function get_link_rel($file){
$h1tags = preg_match_all(‘/(rel=)(“.*”) href=(“.*”)/im’,$file,$patterns);
$res = array();
array_push($res,$patterns);
array_push($res,count($patterns[2]));
return $res;
}

function get_external_css($file){
$h1tags = preg_match_all(‘/(href=”)(\w.*\.css)”/i’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}

// retrieve all h1 tags
function get_h1($file){
$h1tags = preg_match_all(“/(

)(\w.*)()/isxmU”,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}

// retrieve all h2 tags
function get_h2($file){
$h1tags = preg_match_all(“/(

)(\w.*)()/isxmU”,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}

// retrieve all h3 tags
function get_h3($file){
$h1tags = preg_match_all(“/(

)(\w.*)()/ismU”,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}

// retrieve all h4 tags
function get_h4($file){
$h1tags = preg_match_all(“/(

)(\w.*)()/ismU”,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}

// retrieve all h5 tags
function get_h5($file){
$h1tags = preg_match_all(“/(

)(\w.*)()/ismU”,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}

// retrieve all h5 tags
function get_h6($file){
$h1tags = preg_match_all(“/(

)(\w.*)()/ismU”,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}

// retrieve p tag contents
function get_p($file){
$h1tags = preg_match_all(“/(

)(\w.*)()/ismU”,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}

// retrieve names of links
function get_a_content($file){
$h1count = preg_match_all(“/()(\w.*)()/ismU”,$file,$patterns);
return $patterns[2];
}

// retrieve link destinations
function get_a_href($file){
$h1count = preg_match_all(‘/(href=”)(.*?)(“)/i’,$file,$patterns);
return $patterns[2];
}

// get count of href’s
function get_a_href_count($file){
$h1count = preg_match_all(‘/<(a.*) href=\"(.*?)\"(.*)/’,$file,$patterns);
return count($patterns[0]);
}

//get all additional tags inside a link tag
function get_a_additionaltags($file){
$h1count = preg_match_all(‘/(.*)()/’,$file,$patterns);
return $patterns[3];
}

// retrieve span’s
function get_span($file){
$h1count = preg_match_all(‘/()(.*)()/’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}

// retrieve spans on the site
function get_script($file){
$h1count = preg_match_all(‘/()(.*)()/imxsU’,$file,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}

// retrieve content of ul’s
function get_ul($file){
$h1count = preg_match_all(‘/(

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s