|
|
|
| Здравствуйте. Не могу регулярку нормально составить. Нужно что бы
<a href="http://cvbcbv" target="_blank" >c</a> <a href="http://cvbcbv" target="_blank" >e</a><br />
|
пропускался, а менялась часть только когда в ссылке есть rel="nofollow", а оно захватывает две ссылки без rel="nofollow". Т.е, первый оно находит правильно, а вот дальше, он захватывает все до другого нужного урла, включая 2 ненужные ссылки.
<?php
$txt = 'b,mnb b,b ,mnb ,mnb ,mnb m,nb m,nbm,nb<br /><a href="http://gdfgdfgdfg" target="_blank" rel="nofollow">My Webpage</a><a href="http://cvbcbv" target="_blank" >c</a> <a href="http://cvbcbv" target="_blank" >e</a><br /><a href="http://gdfgdfgdfg" target="_blank" rel="nofollow">My Webpage</a>';
echo preg_replace( "#<a href=[\"'](http://|https://|ftp://|ed2k://|news://|magnet:)?(\S.+?)['\"]\s*?[a-zA-Z0-9=_\"]+?\s*?rel=\"nofollow\">(.+?)</a>#s" , "[urln=\\1\\2]\\3[/urln]" , $txt );
?>
|
т.е. надо чтобы было
[urln=http://gdfgdfgdfg]My Webpage[/urln]<a href="http://cvbcbv" target="_blank" >c</a> <a href="http://cvbcbv" target="_blank" >e</a><br />[urln=http://gdfgdfgdfg]My Webpage[/urln]
|
| |
|
|
|
|
автор: _гость_ (23.02.2008 в 05:05) |
|
|
для: Саша
(22.02.2008 в 23:05)
| | так вроде работает
<?php
$txt = <<<TXT
b,mnb b,b ,mnb ,mnb ,mnb m,nb m,nbm,nb<br />
<a href="http://gdfgdfgdfg"
target="_blank" rel="nofollow">My Webpage</a>
<a href="http://cvbcbv"
target="_blank" >c</a>
<a href="http://cvbcbv" target="_blank" >e</a><br />
<a href="http://gdfgdfgdfg" target="_blank" rel="nofollow">My Webpage</a>
TXT;
echo htmlspecialchars(preg_replace( '#<a href=(?:"|\')?(http://|https://|ftp://|ed2k://|news://|magnet:)?([^\'"\s]+)[^>]+?rel="?nofollow"?>(.+?)</a>#s' ,
'[urln=\\1\\2]\\3[/urln]' , $txt ));
?>
|
| |
|
|
|