我有一个长字符串,其中包含一个我想要删除的样式化标记并用其他字符串替换。 但是我试过了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);
“*我想删除并替换其他东西。”“那是什么?你想要取代什么?请更具体地添加更多描述。 – Lion 2012-07-17 10:23:22
@Lion我想替换一些其他的字符串。 – sammyukavi 2012-07-17 10:24:18