【问题标题】:Find a portion of string in a string and change it with PHP [duplicate]在字符串中查找字符串的一部分并使用 PHP [重复]
【发布时间】:2015-10-24 19:40:33
【问题描述】:

我有这个字符串:

 $string= " 22 December-28 December 2015";

在 PHP 中存在一个方法,我可以在 $string 中找到单词“December”并用另一个单词对其进行更改?

我想要一个新的:

 $string= " 22 Dicembre-28 Dicembre 2015";

【问题讨论】:

  • 这个方法是str_replace
  • str_ireplace — str_replace() 的不区分大小写版本。

标签: php string replace


【解决方案1】:

你可以使用str_replace() 函数。

类似这样的:

$string= " 22 December-28 December 2015";
$string = str_replace('December', 'Dicembre', $string);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-01
    • 2011-04-14
    • 1970-01-01
    • 1970-01-01
    • 2020-05-17
    • 2014-05-09
    • 2020-09-26
    • 1970-01-01
    相关资源
    最近更新 更多