如何从字符串中删除最后一次出现的OR

GYa*_*YaN 2 php

我只是想问我想从后面的字符串中删除最后一个OR.

$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';
Run Code Online (Sandbox Code Playgroud)

tan*_*tan 7

$ character表示字符串的结尾.

preg_replace("/OR$/", '', $str );
Run Code Online (Sandbox Code Playgroud)

要么

rtrim($str, ' OR');
Run Code Online (Sandbox Code Playgroud)


Abh*_*jit 5

<?php
$hello ="dddOR";
echo rtrim($hello,"OR");
?>
Run Code Online (Sandbox Code Playgroud)

http://php.net/rtrim