note 60010 deleted from function.preg-replace by felipe
| From: | felipe@php.net | Date: | Mon, 10 Dec 2007 02:07:46 +0000 |
| Subject: | note 60010 deleted from function.preg-replace by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133090@lists.php.net to get a copy of this message | ||
Note Submitter: kyle at vivahate dot com
----
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]