0

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

omkara
  • 964
  • 5
  • 18
  • 47

3 Answers3

3

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);
Abdulla Nilam
  • 31,770
  • 15
  • 58
  • 79
Jouby
  • 1,766
  • 1
  • 22
  • 29
0

You can simply use str_replace()

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

https://eval.in/979310

Anant Kumar Singh
  • 68,309
  • 10
  • 50
  • 94
0

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"
vp_arth
  • 13,847
  • 4
  • 37
  • 62