我需要将所有TYPO3链接更改为真正的a-Tags,因为我想在没有TYPO3的情况下使用它
Text example #1:
$strText = 'This is a <strong>full</strong> Text
<link https://www.example.com/news/test.html#tab3 _blank external-link-new-window "Opens external link in new window">More informations</link><br>
Some more Text <link http://www.example.com>More informations</link>
Text end';
I tried the following regex:
$search = '/<link\s(ftp:\/\/|http:\/\/|https:\/\/|\/)([^\s]+)[^>]*>(.+?)<\/link>/si';
$replace = '<a href="\\1\\2" rel="nofollow" target="_blank" class="external">\\3</a>';
$strText = preg_replace($search, $replace, $strText);
它与此文本完美配合......但是如果链接的顺序在此文本中反转,则它非常错误
Text example #2 which result in problems:
$strText = 'This is a <strong>full</strong> Text
<link http://www.example.com>More informations</link><br>
Some more Text <link https://www.example.com/news/test.html#tab3 _blank external-link-new-window "Opens external link in new window">More informations</link>
Text end';
这会导致链接错误,将两个链接都包含在一个链接中 .
我不明白这个,也无法找到解决方案 .
1 回答
使用此模式: