note 88265 added to function.preg-replace

From: Date: Sun, 18 Jan 2009 10:11:25 +0000
Subject: note 88265 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-149379@lists.php.net to get a copy of this message
In attempt to automatically convert URLs to hyperlinks I adopted the solution offered by tal at ashkenazi dot co dot il However, I ran into problem of tackling previously insert HTML line breaks, which could be solved by <?php $changeThese=array("<br>", "<br />", "<br/>"); $string = str_replace($changeThese," \n<br /> ",$string); // so there is whitespace before running $in=array('((?:https?|ftp)://\S+[[:alnum:]]/?)si', '((?<!//)(www\.\S+[[:alnum:]]/?))si'); $out=array('<a href="$1" >$1</a> ', '<a href="http://$1" >$1</a>'); return preg_replace($in,$out,$string); ?> Known issue is that if there are existing HTML formatted hyperlinks, they will break. ---- Server IP: 80.81.171.181 Probable Submitter: 82.181.100.104 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/88265 Del: integrated -- https://master.php.net/note/delete/88265/integrated Del: useless -- https://master.php.net/note/delete/88265/useless Del: bad code -- https://master.php.net/note/delete/88265/bad+code Del: spam -- https://master.php.net/note/delete/88265/spam Del: non-english -- https://master.php.net/note/delete/88265/non-english Del: in docs -- https://master.php.net/note/delete/88265/in+docs Del: other reasons-- https://master.php.net/note/delete/88265 Reject -- https://master.php.net/note/reject/88265 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149379) next »