我有一个长字符串,其中包含一个样式标记,我想将其删除并替换为其他字符串。但是我尝试了 str_replace 函数,但它失败了。知道我该怎么做吗?我的代码在这里。
$primaryNav = '<li id="menu-item-1178" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1178 sf-ul">
<a href="http://mysite.com/join/" class="sf-with-ul">
<cufon class="cufon cufon-canvas" alt="Get " style="width: 30px; height: 15px; ">
<canvas width="45" height="16" style="width: 45px; height: 16px; top: -1px; left: -2px; "></canvas>
<cufontext>Get </cufontext>
</cufon>
<cufon class="cufon cufon-canvas" alt="in" style="width: 15px; height: 15px; ">
<canvas width="24" height="16" style="width: 24px; height: 16px; top: -1px; left: -2px; "></canvas>
<cufontext>in</cufontext>
</cufon>
<span class="sf-sub-indicator"><cufon class="cufon cufon-canvas" alt="»" style="width: 6px; height: 15px; "><canvas width="20" height="16" style="width: 20px; height: 16px; top: -1px; left: -2px; "></canvas><cufontext>»</cufontext></cufon></span></a>
<ul class="sub-menu" style="visibility: hidden; display: none; "> </ul>
</li>';
$primaryNav = str_replace('<span class="sf-sub-indicator"><cufon class="cufon cufon-canvas" alt="»" style="width: 6px; height: 15px; "><canvas width="20" height="16" style="width: 20px; height: 16px; top: -1px; left: -2px; "></canvas><cufontext>»</cufontext></cufon></span>', ' It works!', $primaryNav);