943,895 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 583
  • PHP RSS
Feb 12th, 2009
0

regex

Expand Post »
anyone can help me to make regular expression

[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?
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
forzadraco is offline Offline
70 posts
since Mar 2008
Feb 12th, 2009
0

Re: regex

Quote ...
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 ?
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Feb 12th, 2009
0

Re: regex

yes remove all if get same pattern.. the problem is how to make regex pattern...
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
forzadraco is offline Offline
70 posts
since Mar 2008
Feb 12th, 2009
0

Re: regex

php Syntax (Toggle Plain Text)
  1. $pattern = "/x{3}/";
  2. $string = preg_replace($pattern,'', $string);
This will look for xxx, if found, replaces it with null.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Feb 12th, 2009
0

Re: regex

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>
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
forzadraco is offline Offline
70 posts
since Mar 2008
Feb 12th, 2009
0

Re: regex

If you want to see if there are 3 or more x's, use:

PHP Syntax (Toggle Plain Text)
  1. $pattern = "/x{3,}/"

The {3} means looking for 3 of the preceding character but {3,} means 3 or more. There's a great tutorial on regex in PHP here: http://www.sitepoint.com/article/reg...pressions-php/
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bastones is offline Offline
7 posts
since Feb 2009
Feb 12th, 2009
0

Re: regex

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 "".
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: nl2br question
Next Thread in PHP Forum Timeline: stopping the script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC