2017-02-03 88 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