3

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?

2 Answers 2

7

I imagine something like this would work:

preg_replace("(<([a-z]+)>.*?</\\1>)is","",$input);
Sign up to request clarification or add additional context in comments.

1 Comment

if the inner html contains HTML tags (such as an anchor <a href...>) this code doesn't work.
1
$string = preg_replace ("/<sup>(.*?)<\/sup>/i", "", $string);

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

4 Comments

Not working, this is the output I'm getting: Priority Mail<sup>&reg;</sup> International
I run the code and it's working, don't know what's problem your side, you can put them into a single Php and try
If you're going to include the tag name, why not just do $string = str_replace("<sup>&reg;</sup>","",$string) or even $string = substr($string,0,13).substr($string,29); and claim it answers the question completely?
I guess, he just want to remove <sup> tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.