note 71779 added to function.preg-replace

From: Date: Fri, 15 Dec 2006 14:28:51 +0000
Subject: note 71779 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-120634@lists.php.net to get a copy of this message
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; ?> ---- Server IP: 81.94.227.69 Probable Submitter: 213.182.207.207 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/71779 Del: integrated -- https://master.php.net/note/delete/71779/integrated Del: useless -- https://master.php.net/note/delete/71779/useless Del: bad code -- https://master.php.net/note/delete/71779/bad+code Del: spam -- https://master.php.net/note/delete/71779/spam Del: non-english -- https://master.php.net/note/delete/71779/non-english Del: in docs -- https://master.php.net/note/delete/71779/in+docs Del: other reasons-- https://master.php.net/note/delete/71779 Reject -- https://master.php.net/note/reject/71779 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120634) next »