HOME       >>       Programming

Preg Replace Problem


Tom743

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?

truefusion

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.


VIEW DESKTOP VERSION REGISTERGET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.