如何在php中使用rtrim函数从url中删除一些字符? [重复]

code:

courses.php?search-result=sap+bo+training+in+india

In this code I am fetching data from mysql and now I want to remove training in india with due to this I am using rtrim() function in php like this:

$course_n = $_GET['search-result'];

Through this I can get the value from url i.e. (sap bo training in india) but when I am using rtrim() function it show me only (sap b) but I want (sap bo) and want to remove (training in india).

$course_n = $_GET['search-result'];
$course_name = rtrim($course_n,"training in india");
echo $course_name;

output:

sap b

So, How can I fix this problem ?Please help me.

Thank You

</div>

You can simply use str_replace()

$course_name = str_replace("training in india",'',$course_n);

https://eval.in/979310

If you want to remove "training in india" in your string, better use str_replace like this

$course_name = str_replace('training in india', '', $course_n);

Your example here is incorrect.

Second param in rtrim is not a string, it is character mask.

So, rtrim($s, 'training in india') is equal to rtrim($s, 'traing d').

It's used by filter for trimmed characters.

I believe, you have used some character mask with 'o' character, and it was trimmed as well.

You should to select some other strategy to cut string from the end.
For example:

$str = 'sap bo training in india';
$cut = preg_quote('training in india');
$result = preg_replace("/\s*$cut\$/", '', $str);
var_dump($result); // "sap bo"