Location: PHPKode > projects > ObsceneClean > altcents.php
<?php
$alternates=array('o'=>'[o\xA2\xA9]','s'=>'[s$]');
function insertalt($match){
  global $alternates;
  return $alternates[strtolower($match[0])]!='' ? $alternates[strtolower($match[0])] : "$match[0]";
}
function checkstr($needle,$haystack){
  echo '<br> next preg_replace $needle=' . $needle;
  $needle=preg_replace_callback('/\S/','insertalt',$needle);
  echo '<br>  next preg_match  $needle=' . $needle;
  $count=preg_match_all("/$needle/i",$haystack,$matches);
  return $count ? "  -count: $count<br>\$matches ".print_r($matches,true) : "no match.";
}
echo '<pre>';
echo '<hr> 1';
echo checkstr('Look','Look up my friend');
echo '<hr> 2';
echo checkstr('Look|Friends','Lo©k up my friend$');
echo '<hr> 3';
echo checkstr('bad','Lo©k up my friend$');
?>
Return current item: ObsceneClean