dongya767979565 2016-08-18 18:04
浏览 20
已采纳

某个字符后删除html代码php [关闭]

Question: I have full html code inserted into mysql database. I want to remove everything after Product Description. How would I do it?

<p>hjfsdgfsgdfjsdgfjgdsjfgsdjgfjsdgf </p>
<p>Product Description</p>

I want to store into the database again with the html format.

  • 写回答

3条回答 默认 最新

  • dongtaotao19830418 2016-08-18 18:33
    关注

    Answering to the question proposed in the comments of your original question, you can do something like this:

    preg_replace("/<div class=\"ui-box product-description-main\".*/sm", " ",$your_html_goes_here);
    

    This removes everything after the div element with classes 'ui-box' and 'product-description-main'.

    By the same token, answering your original question is fairly simple:

    preg_replace("/(<p>Product Description<\/p>).*/sm", "$1", $your_html_goes_here);
    

    This removes everything after the paragraph 'Product Description'. If you need more information about the regex proposed in my answer,let me know.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?