Re: Preg_replace question
| From: | 1LT John W. Holmes | Date: | Thu, 21 Nov 2002 15:36:35 +0000 |
| Subject: | Re: Preg_replace question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-125422@lists.php.net to get a copy of this message | ||
> Following on from a previous discussion, I am trying to write a "safe"
> strip_tags function.
>
> I start by applying htmlentities to the entire string, and then convert
> "allowed" tags back.
>
> One of the steps I am looking at doing is to replace something "<a
> href="blah" onmouseover="blah">" with "<a
> href="blah">"
>
> What would be a good preg_replace string for this?
>
> Preg_replace('/(<A)/i', '<a', $htmlstring);
>
> Except I need to keep the href="<anything>" as well as the closing >,
> but drop everything else.
>
> I will be googling on this too, but a reply from this group is always
> quicker <g>
How about
$new_string = preg_replace('/<a
href="([^"]+)".*>/U','< a
href="$1">',$old_string);
Adapt to your needs...
---John Holmes...