note 60010 added to function.preg-replace

From: Date: Thu, 22 Dec 2005 20:08:44 +0000
Subject: note 60010 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-100591@lists.php.net to get a copy of this message
Here is a regular expression to "slashdotify" html links. This has worked well for me, but if anyone spots errors, feel free to make corrections. <?php $url = '<a attr="garbage" href="http://us3.php.net/preg_replace">preg_replace - php.net</a>'; $url = preg_replace( '/<.*href="?(.*:\/\/)?([^ \/]*)([^ >"]*)"?[^>]*>(.*)(<\/a>)/', '<a href="$1$2$3">$4</a> [$2]', $url ); ?> Will output: <a href="http://us3.php.net/preg_replace">preg_replace - php.net</a> [us3.php.net] ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60010 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60010&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60010&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60010&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60010&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60010&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60010&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60010&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60010&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#100591) next »