Reputation: 2084
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
Upvotes: 0
Views: 119
Reputation: 21531
This would replace the whole word with stars...
$wordlist = "mission|good|praise";
preg_replace("/($wordlist)/ie", 'preg_replace("/./","*","\\1")', $text);
Upvotes: 0
Reputation: 5698
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);
?>
Upvotes: 0