views:

36

answers:

3

Hi friends,

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 consumers 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

+1  A: 
str_replace(array $from, array $to, $source_string)
zerkms
what is that array $from
tibin mathew
$from = array('mission', 'Good'); $to = array('m*****n', 'G**d');ps: php.net/str_replace
zerkms
thanks Zerkms ...
tibin mathew
A: 

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);
?>
karthi_ms
what if he want case insensitivity? ;-)
zerkms
A: 

This would replace the whole word with stars...

$wordlist = "mission|good|praise";
preg_replace("/($wordlist)/ie", 'preg_replace("/./","*","\\1")', $text);
fire