2011-07-22 22 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