简体   繁体   English

PHP str_replace()在条件上有多个参数

[英]PHP str_replace() with multiple parameter on condition

I want to use php str_replace() function on some condition. 我想在某些条件下使用php str_replace()函数。 Eg : if the string has am i want to replace with :00 and if it has pm i want to replace with :00 . 例如:如果字符串am我想要替换:00 ,如果它具有pm我要替换:00 There will be one am or pm on the string and I want to replace with same variable. 字符串上将有一个ampm ,我想用相同的变量替换。 How do I do it using PHP? 我如何使用PHP做到这一点?

 $classRoom->start =Carbon::parse($request->input('start'));
dd(str_replace(array('am', ':00'), array('pm', ':00'),$request->input('start'))); 
str_replace(array('am', 'pm'), ':00', $request->input('start'));

You can pass an array to both of the first parameters for str_replace. 您可以将数组传递给str_replace的两个第一个参数。 You need to pass an array of the text to search for. 您需要传递要搜索的文本数组。 Then you pass an array or string of things to replace. 然后传递要替换的数组或字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM