Jump to content
xisto Community
Sign in to follow this  
Tom743

Preg Replace Problem

Recommended Posts

If i have a word like c.........a......t (with the dots in) and i wanted to replace it with cat how would i do it. If i use

<?php$patterns = "/c(*)a(*)t/";$replace = "cat";echo preg_replace($patterns, $replace, 'c.....a.........t');[/color][color="#000000"]?>

then when i type something like "come and look at this" is also filtered. Is there any way just to filter cat with dots in?

Share this post


Link to post
Share on other sites

If all you want to do is eliminate dots found specifically inbetween the letters "c", "a" and "t", then the following should work:

$patterns = "/c\.{2,}a\.{2,}t/";$replace = "cat";echo preg_replace($patterns, $replace, 'c.....a.........t');
Anything else would require a more complex pattern.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.