Re: strip urls

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxx
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-----

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux