note 75858 added to function.str-replace
| From: | php at gdx dot be | Date: | Tue, 19 Jun 2007 13:33:13 +0000 |
| Subject: | note 75858 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-127784@lists.php.net to get a copy of this message | ||
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);
?>
----
Server IP: 193.190.198.20
Probable Submitter: 87.64.113.21
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- https://master.php.net/note/edit/75858
Del: integrated -- https://master.php.net/note/delete/75858/integrated
Del: useless -- https://master.php.net/note/delete/75858/useless
Del: bad code -- https://master.php.net/note/delete/75858/bad+code
Del: spam -- https://master.php.net/note/delete/75858/spam
Del: non-english -- https://master.php.net/note/delete/75858/non-english
Del: in docs -- https://master.php.net/note/delete/75858/in+docs
Del: other reasons-- https://master.php.net/note/delete/75858
Reject -- https://master.php.net/note/reject/75858
Search -- https://master.php.net/manage/user-notes.php