2017-02-03 89 views
1

我需要改变所有TYPO3链接到真正的一个标签,因为我想用它,而不TYPO3正则表达式TYPO3链接

文本示例#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'; 

我尝试以下正则表达式:

$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); 

它与这段文字可以正常使用......不过这是非常错误,如果林的顺序KS反相本文

文本示例#2导致的问题里面:

$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

为什么不让TYPO3呈现的内容和使用的输出?然后你确定所有链接都能正确显示目标,标题,链接内容等等。 –

回答

0

使用此模式:

/<link\s(ftp:\/\/|https?:\/\/|\/)([^\s]+)[^>]*>(.+?)<\/link>/ig