Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove last occurrence of OR from string

Tags:

php

I just want to ask that I want to remove the last OR from following string.

$string = 'b.dates LIKE "2017-10-13%" OR 
b.dates LIKE "2017-10-14%" OR 
b.dates LIKE "2017-10-15%" OR 
b.dates LIKE "2017-10-16%" OR 
b.dates LIKE "2017-10-17%" OR';
like image 482
GYaN Avatar asked Nov 28 '22 06:11

GYaN


1 Answers

$ character indicates the end of string.

preg_replace("/OR$/", '', $str );

or

rtrim($str, ' OR');
like image 113
tan Avatar answered Dec 10 '22 20:12

tan