Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP str_replace() with multiple parameter on condition

Tags:

php

laravel

I want to use php str_replace() function on some condition. Eg : if the string has am i want to replace with :00 and if it has pm i want to replace with :00. There will be one am or pm on the string and I want to replace with same variable. How do I do it using PHP?

 $classRoom->start =Carbon::parse($request->input('start'));
dd(str_replace(array('am', ':00'), array('pm', ':00'),$request->input('start'))); 
like image 204
Hola Avatar asked May 09 '26 12:05

Hola


1 Answers

str_replace(array('am', 'pm'), ':00', $request->input('start'));

You can pass an array to both of the first parameters for 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.

like image 144
Brett Avatar answered May 12 '26 02:05

Brett