我们想使用 preg_replace 进行查找和替换。但无法得到想要的结果
这是我的字符串
$x = '<a href="http://atlasshrugs2000.typepad.com/atlas_shrugs/2005/11/i_leave_shreds_.html#comment-11657412">FALLACI</a>';
$x .= '<a href="http://atlasshrugs2000.typepad.com/atlas_shrugs/2005/10/i_leave_shreds_.html#comment-11657412">FALLACI</a>';
$x .= '<a href="http://atlasshrugs2000.typepad.com/atlas_shrugs/20>';05/1/i_leave_shreds_.html#comment-11657412">FALLACI</a>';
$x .= '<a href="http://atlasshrugs2000.typepad.com/atlas_shrugs/2005/9/i_leave_shreds_.html#comment-11657412">FALLACI</a>';
$x .= '<a href="http://atlasshrugs2000.typepad.com/atlas_shrugs/2006/11/i_leave_shreds_.html#comment-11657412">FALLACI</a>';
$x .= '<a href="http://atlasshrugs2000.typepad.com/atlas_shrugs/i_leave_shreds_.html#comment-11657412">FALLACI</a
echo preg_replace('/<a(.*?)href="http:\/\/atlasshrugs2000.typepad.com\/atlas_shrugs\/([0-9\/]{0,7}?)(.*?)_.html#(.*?)"(.*?)>/','<a$1href="http://localhost/test/$3#$4"$5>',$x);
它给出了以下结果
<a href="http://localhost/test/2005/11/i_leave_shreds#comment-11657412">FALLACI</a>
<a href="http://localhost/test/2005/10/i_leave_shreds#comment-11657412">FALLACI</a>
<a href="http://localhost/test/2005/1/i_leave_shreds#comment-11657412">FALLACI</a>
<a href="http://localhost/test/2005/9/i_leave_shreds#comment-11657412">FALLACI</a>
<a href="http://localhost/test/2006/11/i_leave_shreds#comment-11657412">FALLACI</a>
<a href="http://localhost/test/i_leave_shreds#comment-11657412">FALLACI</a>
但我们想要像这样的结果
<a href="http://localhost/test/i_leave_shreds#comment-11657412">FALLACI</a>
<a href="http://localhost/test/i_leave_shreds#comment-11657412">FALLACI</a>
<a href="http://localhost/test/i_leave_shreds#comment-11657412">FALLACI</a>
<a href="http://localhost/test/i_leave_shreds#comment-11657412">FALLACI</a>
<a href="http://localhost/test/i_leave_shreds#comment-11657412">FALLACI</a>
<a href="http://localhost/test/i_leave_shreds#comment-11657412">FALLACI</a>
请帮我。提前致谢 :)