note 38464 added to function.preg-replace

From: Date: Mon, 22 Dec 2003 22:11:31 +0000
Subject: note 38464 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-62358@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38464 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38464&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38464&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#62358) next »