note 95976 added to function.preg-replace

From: Date: Mon, 01 Feb 2010 11:18:05 +0000
Subject: note 95976 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-165548@lists.php.net to get a copy of this message
Here is an example of configurable regular expression for converting urls to html links from http://www.devhands.com/2010/02/php-preg_replace-url/ <?php // configurable delimiters and schemes $delimiters = '\\s"\\.\','; $schemes = 'https?|ftps?'; // build pattern $pattern = sprintf('#(^|[%s])((?:%s)://\S+[^%1$s])([%1$s]?)#i', $delimiters, $schemes); $replacement = '$1<a href="$2">$2</a>$3'; $subjects = array( 'http://localhost', 'prefix "http://example.com/path&var=val" suffix', // ... ); foreach ($subjects as $subject) { var_dump(preg_replace($pattern, $replacement, $subject)); } ?> ---- Server IP: 212.126.36.70 Probable Submitter: 79.125.6.243 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/95976 Del: integrated -- https://master.php.net/note/delete/95976/integrated Del: useless -- https://master.php.net/note/delete/95976/useless Del: bad code -- https://master.php.net/note/delete/95976/bad+code Del: spam -- https://master.php.net/note/delete/95976/spam Del: non-english -- https://master.php.net/note/delete/95976/non-english Del: in docs -- https://master.php.net/note/delete/95976/in+docs Del: other reasons-- https://master.php.net/note/delete/95976 Reject -- https://master.php.net/note/reject/95976 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#165548) next »