Created
May 3, 2014 00:56
-
-
Save madeinnordeste/e071857148084da94891 to your computer and use it in GitHub Desktop.
PHP - Remove URLs from string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$string = 'Hi, visit my website: http://beto.euqueroserummacaco.com'; | |
$string = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $string); | |
echo $string; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If your URL begins simply with www and no protocol, modify it like this to filter it:
$string = preg_replace('/\b((https?|ftp|file):\/\/|www\.)[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', ' ', $string);