3

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

1 Answer 1

7
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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.