Seek master, look at this paragraph is what wrong??
Requirement: Extract the hyperlink inside the href in the string $str, if the extracted hyperlink contains "id= number", replace it with go.php?id= number, otherwise replace with #, and replace the link back to the same place, now the situation is, although can be extracted, But when we put back the whole label is replaced, I just want to replace the URL within the href, where error??
$str = ";
$str =preg_replace (' [a-za-z]+://[^\s]* ', ' Endecode::showdescurl ' ("$") ', $str);
Echo $str;
Static methods for the Endecode class: The Showdescurl code is as follows:
PHP Code
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 (" $ ") ', $str);