note 71684 added to function.preg-replace

From: Date: Mon, 11 Dec 2006 21:54:10 +0000
Subject: note 71684 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-120519@lists.php.net to get a copy of this message
Ok, this little script is *supposed to* make my life easier by automatically generating links for matched strings, but it's not replacing properly with the $links element that corresponds with the $terms element. It's just putting "Array" in where the $links element should be. The examples for this function are atrocious for beginners, btw. <?php $what = $_POST['url']; $source = file_get_contents($what); $terms = explode(",", file_get_contents('engTerms.txt')); $links = explode(",", file_get_contents('engLinks.txt')); $whatsnew = preg_replace($terms, '<a href="' . $links . '">$0</a>', $source); echo $whatsnew; ?> Please note that '/' have been added to the terms and I've tried to reference the $terms key, but that seems to always eval to '0' so I get the first link in $links in all the replacements! UGH! This *SHOULD* be really easy to do!!! ---- Server IP: 216.194.113.175 Probable Submitter: 128.173.49.6 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/71684 Del: integrated -- https://master.php.net/note/delete/71684/integrated Del: useless -- https://master.php.net/note/delete/71684/useless Del: bad code -- https://master.php.net/note/delete/71684/bad+code Del: spam -- https://master.php.net/note/delete/71684/spam Del: non-english -- https://master.php.net/note/delete/71684/non-english Del: in docs -- https://master.php.net/note/delete/71684/in+docs Del: other reasons-- https://master.php.net/note/delete/71684 Reject -- https://master.php.net/note/reject/71684 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120519) next »