note 38464 deleted from function.preg-replace by tularis
| From: | tularis@php.net | Date: | Sun, 18 Jun 2006 13:16:52 +0000 |
| Subject: | note 38464 deleted from function.preg-replace by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114300@lists.php.net to get a copy of this message | ||
Note Submitter: martin at vertikal dot dk
----
Opposite most expamles mentioned here, I needed to replace "proper" HTML-formatted
URL's with stripped down http-URL's to be used in a non-HTML newsletter. This would enable
non-HTML newsletter subscribers to click directly on the URL.
This small function did it for me:
$txt = preg_replace("/<a href=\"(.*)\">(.*)<\/a>/i", "\\2
(\\1)", $txt);
This will strip the tag <a href="xxx"> and its matching closing tag </a> but
keep the text (here: xxx) between them. After this it will place the original URL in parenthesis.
You can fiddle the sequence and formatting of the variables 1 (URL) and 2 (link text) as you please.
I can now pass the result of a text with HTML-formatted URL's from my CMS directly through this
small funtion and into an email.
I haven't tested this thoroughly with all types of text, complex HTML or strange URL's,
but it works well in my controlled environment.
Martin