anyone can help me to make regular expression

$string=" xxxxx xxxxx <body border='0'> <script language=javascript> ... word1 ... word2 ... word3... word4 ... </script>

";

i want to remove all word from that string if that string have minimal three word'x'

preg_replace(); how to make that regex?[code ]

$string="
xxxxx
xxxxx
<body border='0'>
<script language=javascript>
...
word1 ... word2 ... word3... word4
...
</script>

";

i want to remove all word from that string if that string have minimal three word'x'

preg_replace(); how to make that regex?

Recommended Answers

All 6 Replies

i want to remove all word from that string if that string have minimal three word'x'

I am not clear what you want. Do you want to search for xxx, if found, remove it ?

yes remove all if get same pattern.. the problem is how to make regex pattern...

$pattern = "/x{3}/";
$string = preg_replace($pattern,'', $string);

This will look for xxx, if found, replaces it with null.

not like that.. iwant to remove all from <script> tag till </script> if match with the pattern..

the pattern from
<script .....>
... targetword1..
... targetword2..
... targetword3..

</script>

This isn't the best solution (Infact, its kinda sloppy!). First, use preg_match to search for pattern "xxx". If found, then, use preg_match again, but this time, search for pattern, '/<script[^>]+\>(.*)<\/script>/s' . This will again return the string between <script> tags. Then use str_replace and replace the matched string with "".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.