Please take a look at what is wrong with this regular expression ?? This post is finally edited by dz215136304 from 2012-07-0508: 54: 58. the hyperlink in & nbsp; href in the string $ str & nbsp; is extracted, replace the extracted hyperlink with go. php? Id number. otherwise, replace it with # and put the replaced link back to its original location. the current situation is to be a master. what is wrong with this regular expression ??
This post was last edited by dz215136304 at 08:54:58
Requirement: extract the hyperlink from the href in the string $ str. if the extracted hyperlink contains "id = number", replace it with go. php? Id = number. otherwise, replace it with # and put the replaced link back to its original location. the current situation is that although it can be extracted, but I replaced all the labels when I put them back to the original position. now I only want to replace the URLs in href. what is the error ??
$ Str = '';
$ Str = preg_replace ('[a-zA-z] +: // [^ \ s] *', 'endecode: showdescurl ("$2 ")', $ str );
Echo $ str;
The static method of the endecode class: showdescurl code is as follows:
static function showdescurl($url){
if(strpos($url,'id') !==false){
preg_match('/id=(\d+)/i',$url,$ar);
return 'go.php?id='.$ar[1];
}else{
return '#';
}
}
------ Solution --------------------
$ Str = preg_replace ('#(? <= Href ...) ([a-zA-z] +: //) ([^ \ '"] *) # e', 'endecode: showdescurl (" $2 ")', $ str );