Here is the code
<?php
$url='http://isrc.ulster.ac.uk';
$var = fread_url($url);// function calling to get the page from curl
$i=0;
$linklabel = array();
$linklabelmod = array();
$link = array();
$dom = new DOMDocument();
@$dom->loadHTML($var);
$xpath = new DOMXPath($dom);
foreach($xpath->query('//a') as $element) {
$linklabel[] = $element->textContent;
$link[] = $element->getAttribute("href");
$i=$i+1;
}
for($k=0;$k<$i;$k++) {
$linklabelmod[$k] = str_replace($linklabel[$k], $linklabel[$k]."[$k]", $linklabel[$k]);
$var = preg_replace( "/\\Q$linklabel[$k]\\E/", $linklabelmod[$k], $var, 1 );//modifying link labels
}
print $var;
function fread_url($url){
if(function_exists("curl_init")){
$ch = curl_init();
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; "."Windows NT 5.0)";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt( $ch, CURLOPT_HTTPGET, 1 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
$html = curl_exec($ch);
//print $html;//will printing the web page .
curl_close($ch);
}
else{
$hfile = fopen($url,"r");
if($hfile){
while(!feof($hfile)){
$html.=fgets($hfile,1024);
}
}
}
return $html;
}
?>
Not all link labels are changing. I want each link label to be modified by attaching a unique number. Plz run the code so that you can see error.. Thx in advance..