Word comparing and replacing
I need some comparing and replacing code in PHP
Our mission is to empower consumers to Praise Good Service when they receive it and to Report Poor Service wherever they have to endure it.
I need this paragraph to xcompare for some words (for example mission, Good ) and replace that word like this m*****n and G**d
So the result will be like this
Our m*****n is to empower consum开发者_开发知识库ers to Praise G**d Service when they receive it and to Report Poor Service wherever they have to endure it.
How can i do this in PHP?
Please share your ideas and code if any.
Thanks
str_replace(array $from, array $to, $source_string)
Try this ,
<?php
$str="Our mission is to empower consumers to Praise Good Service when they receive it and to Report Poor Service wherever they have to endure it.";
$trans = array("mission" => "m***n", "Good" => "G**d");
echo strtr($str, $trans);
?>
This would replace the whole word with stars...
$wordlist = "mission|good|praise";
preg_replace("/($wordlist)/ie", 'preg_replace("/./","*","\\1")', $text);
精彩评论