Erhm.. Basically, would something like this work?
Code: Select all
#(^|\s)blah(\s|$)#iModerator: General Moderators
Code: Select all
#(^|\s)blah(\s|$)#iCode: Select all
<?php
$text = "You r a whatever";
$pattern = "/(^|\s)r(\s|$)/is";
$replacement = " are ";
echo preg_replace($pattern,$replacement,$text);
?>Code: Select all
preg_replace('/\br\b/i', 'are', $data);Code: Select all
preg_replace('/(?<!\\)\br\b/i', 'are', $data);Code: Select all
$content = "u r a cool person";
// create arrays
$array_original = array("u", "r"); // words to replace
$array_replace = array("you", "are"); // words to replace WITH
// now convert
$content = str_replace($array_original, $array_replace, $content);There's a big advantage to preg_ with some words.malcolmboston wrote:something this simple i would generally not use preg
eg of what i do..usage: just keep adding to the arrays, make sure that they are in the appropriate part of the arrayCode: Select all
$content = "<span style='color:blue' title='ignorance is bliss'>you</span> <span style='color:blue' title='ignorance is bliss'>are</span> a cool person"; // create arrays $array_original = array("<span style='color:blue' title='ignorance is bliss'>you</span>", "<span style='color:blue' title='ignorance is bliss'>are</span>"); // words to replace $array_replace = array("you", "are"); // words to replace WITH // now convert $content = str_replace($array_original, $array_replace, $content);
Code: Select all
$bad = array(
'/(?<!\\\\)\br\b/i',
'/(?<!\\\\)\bn\b/i',
'/(?<!\/)\bu\b/i',
'/\b(t)h(?:an)x\b/i',
'/!!(?:!)+/',
'/\by\b/i',
'/(?<!\/|\[)\bi\b/',
'/\b(n)oone\b/i',
'/\bdat\b/i',
'/\bsi\b/i',
'/\b(sooo)o+\b/i',
'/\b(d)ud\b/i',
'/\bur\b/i',
'/\b(y)oure\b/i',
'/\bi(m|ll|ve)\b/i',
'/\b(ca|wo|do|did|was)nt\b/i',
'/\b(p)pl\b/i',
'/\b(w)elcom\b/i',
'/\bnoe\b/i',
'/\b(m)abye\b/i',
'/\b(g)[2t](g)\b/i',
'/\bne(?=\b|one)/i',
'/\bne1\b/i',
'/\b(r)ealli\b/i',
);
$b = '<span style="color: #00c;" class="ltt">'; $e = '</span>';
$good = array(
$b.'are'.$e,
$b.'in'.$e,
$b.'you'.$e,
$b.'\\1hanks'.$e,
$b.'!!'.$e,
$b.'why'.$e,
$b.'I'.$e,
$b.'\\1o one'.$e,
$b.'that'.$e,
$b.'is'.$e,
$b.'\\1'.$e,
$b.'\\1ude'.$e,
$b.'you\'re'.$e,
$b.'\\1ou\'re'.$e,
$b.'I\'\\1'.$e,
$b.'\\1n\'t'.$e,
$b.'\\1pl'.$e,
$b.'\\1elcome'.$e,
$b.'know'.$e,
$b.'\\1aybe'.$e,
$b.'\\1ot to \\2o'.$e,
$b.'any'.$e,
$b.'anyone'.$e,
$b.'\\1eally'.$e,
);
$txt = preg_replace($bad,$good,$txt);