单词比较和替换

发布于 2024-08-24 13:34:28 字数 355 浏览 4 评论 0原文

我需要一些 PHP 中的比较和替换代码

我们的使命是让消费者能够 当他们收到时赞扬良好的服务 并在任何地方报告不良服务 他们必须忍受它。

我需要这一段来比较某些单词(例如 Mission、Good )并像这样替换该单词 m*****n 和 G**d

所以结果将是这样的

我们的目标是让消费者能够 当他们收到时赞美上帝的服务 并在任何地方报告不良服务 他们必须忍受它。

我怎样才能在 PHP 中做到这一点?

请分享您的想法和代码(如果有)。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

十二 2024-08-31 13:34:28
str_replace(array $from, array $to, $source_string)
str_replace(array $from, array $to, $source_string)
够运 2024-08-31 13:34:28

试试这个,

<?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);
?>

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);
?>
笑咖 2024-08-31 13:34:28

这会将整个单词替换为星星......

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

This would replace the whole word with stars...

$wordlist = "mission|good|praise";
preg_replace("/($wordlist)/ie", 'preg_replace("/./","*","\\1")', $text);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文