2011-07-22 117 views
-2

還有一個文字中有更多的單詞,有些是英文,有些是latins,現在,如何使用preg_replace,打破所有鏈接#?使類似:php preg_replace所有鏈接#

<a href="#next">flow to the next</a> =>flow to the next? (僅在長文本打破了鏈接與#

感謝。

不適合這項工作。

$new = preg_replace('/<a(?:.*?)(href="#)(?:.*?)>(.*?)<\/a>/is', '$2', $old); 
// this will also broken other links... 

回答

1
<?php 
$old = '<a href="#next">flow to the next</a> '; 
$new = preg_replace('/(<a href="\#.*?">)(.*?)<\/a>/is', '$2', $old); 
echo $new; 

demo