Re: strip urls

From: Date: Mon, 11 Sep 2006 18:15:18 +0000
Subject: Re: strip urls
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-241618@lists.php.net to get a copy of this message
Thank you! That workes excellent! Merlin Christopher Weldon schrieb:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Merlin wrote:
RalfGesellensetter schrieb:
Am Montag 11 September 2006 15:36 schrieb Merlin:
I am trying to strip URL's out of a text. There is a function for this in php, but I can't find it anywhere. Can sombody help?
hi, it's strip_tags and only removes the tags (<a href ...) but keeps the plain text that would be displayed in a text browser.
Hi there, thank you for the hint. This it the one I was searching for. However unfortunatelly the function also strips all other tags! I am looking for one that only does strip the <a href tag. I am not so familar with regex, but I fear I would need to :-( My guess is that it must be something like this: $str = 'foo <a href="">test</a> o'; $str = preg_replace('<a (.*)', '', $str); echo $str; Can anybody help me on that? Thank you so much in advance. Regards, Merlin
Two things: First, you can actually specify which tags you don't want strip_tags to take out. Say for example you want <p> and <br /> tags to remain in the string: $string = strip_tags($string, '<p><br />'); Second, don't forget the tags you'll need in the preg_replace function: $str = preg_replace('/\<a href="([^\"]*)"[^\>]*\>/', "\1", $str); You can use other characters, such as ! if you want instead of /, but you have to use the same at the beginning and the end. - -- Christopher Weldon, ZCE President & CEO Cerberus Interactive, Inc. cweldon@cerberusonline.com 979.739.5874 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFBZ9yZxvk7JEXkbERAhuUAJ4o4rBiypj2OwpHjrUj2e0XZ8FVhQCeJZ6e eCOa+PYkyrRacqnT5VtoL/A= =/r2e -----END PGP SIGNATURE-----


« previous php.general (#241618) next »