A forum program, the link in the user post (* Not the site's domain name of the link) all replaced by the specified connection
For example, source code:
-------------------------------------------------
Aaaaabbbbbcccccdddddeeeeefffffggggg
-----------------------------------------------------------
Replaced by
-----------------------------
Aaaaabbbbbcccccdddddeeeeefffffggggg
------------------------
Requirement: Replace all links under non-aaa.com domain name with "#" pound sign
The following code can replace all links as the pound sign, but cannot tell if it is aaa.com
echo Preg_replace ("/(? <=href=) ([^\>]*) (?=\>)/I", "javascript:;", "Hello, click here to see Hello, click here to see");
Ask the great God help ha very anxious not to get out of the morning
Reply to discussion (solution)
$str = <<
Replace it with the drop thank you ha
Aaaaabbbbcccccdddddeeeeefffffggggg
echo Preg_replace_callback ("/([^<]+) <\/a>/is", function ($r) {return strip_tags ($r [0]);}, $STR);
Thanks microlab2009
But in the application, I tested it and found a few problems.
1: Replace the non-site chain replacement of the pound, but the link is also replaced Oh!
For example: and www.163.com (string non-link) are all replaced by the # number
2: Delete link
bbbbb
And
bbbbb
Error on processing, can modify the first one cannot modify the second one.
Hope the great God to help Ah, infinite gratitude has been Chung centripetal mouth ....
1.
$str = <<
AAAAA
bbbbb
Ccccc
Ddddd
Eeeee
FFFFF
Ggggg
Http://234r.231.com
Str
echo Preg_replace_callback ("/(? <=href\=\") http\:\/\/[^.] *[^a]+\.com\//is ", function ($r) {return str_replace ($r [0]," # ", $r [0]);}, $STR);
?>
2.echo Preg_replace_callback ("/]*> ([^<]+) <\/a>/is", function ($r) {return strip_tags ($r [0]);}, $STR);
You just have to change it, or you have to go ahead and get familiar with the regular.
Thank you very much for the help of God, ha ~ ~ ~