note 71779 deleted from function.preg-replace by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 20:07:40 +0000 |
| Subject: | note 71779 deleted from function.preg-replace by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127716@lists.php.net to get a copy of this message | ||
Note Submitter: Chortos-2 <chortos at inbox dot lv>
----
Iâve fixed the jlockharâs code, so that it works with any content of the terms, including
slashes etc., as well as any version of PHP (well, any version that supports the functions used in
the code).
<?php
// Get the input
$content = file_get_contents($_POST['url']);
$terms = explode(',', file_get_contents('engTerms.txt'));
$links = explode(',', file_get_contents('engLinks.txt'));
// Parse the terms
foreach ($terms as $i => $term)
{
$content = preg_replace('/' . preg_quote($term, '/') . '/',
'<a href="' . htmlentities($links[$i]) . '">$0</a>',
$content);
}
echo $content;
?>