0

I have a string like this:

$mystring = "some words1 some more words2 <script>some variable inside</script> some more words3";

I want to remove script tags and inside it. I want to have "some words1 some more words2 some more words3" How can I remove that part

1
  • "Remove variable in string" - Remove what variable? The title and question are unclear. There are no variables here. Commented Apr 17, 2018 at 11:24

1 Answer 1

1

Try this solution

$srting = 'some words1 some more words2 <script>some variable inside</script> some more words3';

echo strip_tags_content($srting);

function strip_tags_content($text) {
    return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text);
 }

// Only For script tags

preg_replace('(<script>(.*?)</script>)', '', $text);  

// output :some words1 some more words2 some more words3

Sign up to request clarification or add additional context in comments.

2 Comments

How can we edit this function to remove just between <script> </script> I have some other <div> 's in string. It remove all
updated my answer :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.