str()
Posted: Wed Jun 23, 2004 10:44 am
Code: Select all
<?php
$newpostinfo = str_replace('swearword','*****',$newpostinfo);
?>A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
$newpostinfo = str_replace('swearword','*****',$newpostinfo);
?>Code: Select all
<?php
if (!function_exists('str_ireplace'))
{
function str_ireplace($search, $replace, $subject, $count = 0)
{
$subject_array = true;
if (is_array($search) && is_string($replace))
{
$replace = array($replace);
for ($i = 1, $max = count($search); $i < $max; $i++)
{
$replace[] = $replace[0];
}
}
$search = !is_array($search) ? array($search) : $search;
$replace = !is_array($replace) ? array($replace) : $replace;
if (!is_array($subject))
{
$subject = array($subject);
$subject_array = false;
}
for ($i = 0, $sub_size = count($subject); $i < $sub_size; $i++)
{
for ($j = 0, $limit = count($search); $j < $limit; $j++)
{
$search_str = '/' . preg_quote($search[$j]) . '/i';
$count += preg_match_all($search_str, $subject[$i], $notused);
$search_array[] = $search_str;
}
}
$subject = preg_replace($search_array, $replace, $subject);
return $subject_array ? $subject : $subject[0];
}
}
?>