PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$pattern = "/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}/i";
$string = "My URL is example.co.uk. Please visit my site."
echo preg_replace($pattern, "***", $string);
//Outputs: My URL is ***. Please visit my site.
//But if there is no space after the end of the first sentence
$string = "My URL is example.co.uk.Please visit my site."
echo preg_replace($pattern, "***", $string);
//Outputs: My URL is *** visit my site.
What can I do to my regular expression so it keeps the start of the second sentence?
<?php
$pattern = "/[a-z0-9\-\.]+\.[a-z]{2,6}(\.)/i";
$string = "My URL is example.co.uk. Please visit my site.";
echo preg_replace($pattern, "***", $string).'<p>';
//Outputs: My URL is ***. Please visit my site.
//But if there is no space after the end of the first sentence
$string = "My URL is example.co.uk.Please visit my site.";
echo preg_replace($pattern, "***$1", $string);
//Outputs: My URL is *** visit my site.
?>
EDIT:
Sorry that was right, it does work perfect... could just be written a bit better.