preg_replace第二个参数 ($replacement) 不适合


preg_replace second parameter ($replacement) doesnt fit

我在Wordpress中的文章内容是一个很大的标记。它来自MS Word,因此它是由HTML嵌套标签和内联样式包装的文本。

我有一段代码在内容中重复了很多次(它表示文本脚注)。例如,对于第一个脚注,此段是:

<sup><a title="" href="file:///C:/Users/hp/Desktop/file.docx#_ftn1" name="_f
tnref1">
 <span class="MsoFootnoteReference">
  <span dir="LTR">
   <span class="MsoFootnoteReference">
    <span lang="EN-US" style="font-size: 16pt; line-height: 115%;">
     [1]
    </span>
   </span>
  </span>
 </span>
</a></sup>
.....
<a title="" href="file:///C:/Users/hp/Desktop/file.docx#_ftnref1" name="_ftn1">
 <span class="MsoFootnoteReference">
  <span dir="LTR" lang="EN-US" style="font-size: 12.0pt; font-family: 'Simplified Arabic','serif';">
   <span class="MsoFootnoteReference">
    <span lang="EN-US" style="font-size: 12pt; line-height: 115%;">
     [1]
    </span>
   </span>
  </span>
 </span>
</a>

我的目标是将 2 个 hrefs 从:

href="file:///C:/Users/hp/Desktop/file.docx#_ftn1" 
href="file:///C:/Users/hp/Desktop/file.docx#_ftnref1"

自:

href="#_ftn1" 
href="#_ftnref1"

以便用户可以从一个定位点跳到另一个锚点。

我使用的代码是:

if(preg_match_all('/href's*='s*"[^"]+(#[^"]+)"/',get_the_content(),$match))
{
echo preg_replace('/href's*='s*"[^"]+(#[^"]+)"/','href=""', get_the_content()); 
}

提前非常感谢您的宝贵帮助。

找到了解决方案。谢谢你的时间。

   if(preg_match_all('/href's*='s*"[^"]+(#[^"]+)"/',get_the_content(),$match))
    {
    echo preg_replace('/href's*='s*"[^"]+(#[^"]+)"/','href="$1"', get_the_content()); 
    }