note 75858 deleted from function.str-replace by nlopess

From: Date: Tue, 19 Jun 2007 17:05:28 +0000
Subject: note 75858 deleted from function.str-replace by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-127791@lists.php.net to get a copy of this message
Note Submitter: php at gdx dot be ---- bate2web: you can better use substr or preg match, I guess! <?php function make_valid_url($site) { if(substr($site, 7) != 'http://' AND substr($site, 8) != 'https://') { return 'http://'.$site; } } ?> however, str_replace is helpfull to create some links behind keywords in a blog. I wrote this script for my blog (at http://www.gdx.be/, it's in dutch!): <?php $search = array(); $replace = array(); $query = $mysql->query("SELECT string,link FROM blog_replace WHERE active='1'"); while ($links = mysql_fetch_object($query)) { // lets build 2 arrays, one for the search pattern, and one for the replacement! $search[] = ' '.$links->string; // yes, with a space! We do not want links with another link in it! (or just words with half a link behind it!) $replace[] = ' <a href="'.$links->link.'" target="_blank" class="bloglink">'.$links->string.'</a>'; } // usage: // $blogmessage = str_replace($search, $replace, $blogmessage); ?>

« previous php.notes (#127791) next »