0

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?

3
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by nav33n
0

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 ?

0

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

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

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

0

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>

0

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 "".

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.