PHP Preg expression to remove html tags and inner contents from string?

跟風遠走 提交于 2019-12-12 09:47:46

问题


quick question.

I'd like to remove the sup tag from the following string, and all content within it.

$string = "Priority Mail<sup>&reg;</sup> International";

How would I do that?


回答1:


I imagine something like this would work:

preg_replace("(<([a-z]+)>.*?</\\1>)is","",$input);



回答2:


$string = preg_replace ("/<sup>(.*?)<\/sup>/i", "", $string);

You should know that (.*?) can't deal with \n or \r, so filter them first.



来源:https://stackoverflow.com/questions/10508801/php-preg-expression-to-remove-html-tags-and-inner-contents-from-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!