Re: [PHP] preg_replace anything that isn't WORD

2009-08-24 Thread Jonathan Tapicer
For the record Shawn: I received your previous post from Aug 22 and I think that it is the best solution. Jonathan On Tue, Aug 25, 2009 at 12:41 AM, Shawn McKenzie wrote: > hack988 hack988 wrote: >>  Use preg_replace_callback instead! >> preg_replace_callback is better performance than preg_repla

Re: [PHP] preg_replace anything that isn't WORD

2009-08-24 Thread Shawn McKenzie
hack988 hack988 wrote: > Use preg_replace_callback instead! > preg_replace_callback is better performance than preg_replace with /e. > - > code > > $str="cats i saw a cat and a dog"; > $str1=preg_replace_callback("/(

Re: [PHP] preg_replace anything that isn't WORD

2009-08-24 Thread hack988 hack988
Use preg_replace_callback instead! preg_replace_callback is better performance than preg_replace with /e. - code $str="cats i saw a cat and a dog"; $str1=preg_replace_callback("/(dog|cat|.)/is","call_replace",$str);

Re: [PHP] preg_replace anything that isn't WORD

2009-08-24 Thread tedd
On Sat, Aug 22, 2009 at 12:32 PM, “•ÈýÏݓ•ÂÔ wrote: Lets assume I have the string "cats i saw a cat and a dog" i want to strip everything except "cat" and "dog" so the result will be "catcatdog", using preg_replace. I've tried something like /[^(dog|cat)]+/ but no success > What should

Re: [PHP] preg_replace anything that isn't WORD

2009-08-22 Thread Jonathan Tapicer
Negating specific words with regexes isn't a good practice (see a deep discussion here: http://www.perlmonks.org/?node_id=588315), in your case I would resolve it like this: That will output: array(5) { [0]=> string(3) "cat" [1]=> string(10) "s i saw a " [2]=> string(3) "cat" [3]=

[PHP] preg_replace anything that isn't WORD

2009-08-22 Thread דניאל דנון
Lets assume I have the string "cats i saw a cat and a dog" i want to strip everything except "cat" and "dog" so the result will be "catcatdog", using preg_replace. I've tried something like /[^(dog|cat)]+/ but no success What should I do? -- Use ROT26 for best security