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
  • 974
  • 5
  • 24
  • 50

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
  • 36,589
  • 17
  • 64
  • 85
Jouby
  • 2,196
  • 2
  • 21
  • 33
0

You can simply use str_replace()

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

https://eval.in/979310

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
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
  • 14,461
  • 4
  • 37
  • 66