0

I have this string variable in my PHP code: I am getting this value from DB.

$includes = "~ All taxes<br/>~ Complimentary Buffet Breakfast,<br/>~ Complimentary Wi-Fi<br/>~ Complimentary Fruit Basket only for Suite Room<br/><br/>Facilities and Services:<br/>~ 24Hrs Room Service<br/>~ Lounge<br/>~ Direct Dialing STD and ISD facilities <br/>Kindly Note:<br/>Before 72Hrs Cancellation full refund";

How to remove this sentence ('Kindly Note: Before 72Hrs Cancellation full refund') from the string.

I have to remove the text which come after this text('Kindly Note:') from the given string How to do that.

Some time I get different text after this text('Kindly Note: We dont allow 24hrs checkin') So I want to remove text whatever comes after this text('Kindly Note:');

Suresh Pattu
  • 6,083
  • 16
  • 59
  • 91

7 Answers7

2

use chop()

echo chop($includes,'Before 72Hrs Cancellation full refund');

or

echo chop($includes,'Kindly Note:<br/>Before 72Hrs Cancellation full refund');

Edit 1

use

echo substr($includes, 0, strpos($includes, "Kindly Note:"));
momouu
  • 711
  • 4
  • 14
2

Since I love exploding things...try this logic, will remove anything beyond the "Kindly Note:" part:

$includes = "~ All taxes<br/>~ Complimentary Buffet Breakfast,<br/>~ Complimentary Wi-Fi<br/>~ Complimentary Fruit Basket only for Suite Room<br/><br/>Facilities and Services:<br/>~ 24Hrs Room Service<br/>~ Lounge<br/>~ Direct Dialing STD and ISD facilities <br/>Kindly Note:<br/>Before 72Hrs Cancellation full refund";
$arr_includes = explode('Kindly Note:', $includes);
$include = $arr_includes[0];

output:

~ All taxes
~ Complimentary Buffet Breakfast,
~ Complimentary Wi-Fi
~ Complimentary Fruit Basket only for Suite Room

Facilities and Services:
~ 24Hrs Room Service
~ Lounge
~ Direct Dialing STD and ISD facilities

Ceeee
  • 1,392
  • 2
  • 15
  • 32
1

Use str_replace simply.

str_replace('Kindly Note:<br/>Before 72Hrs Cancellation full refund', '', $includes);
Sanjay Kumar N S
  • 4,653
  • 4
  • 23
  • 38
0

Simple:

 if ($dbText === 'your text') {
     $dbText = 'your replacement text';
 }

or change the text in the database itself. If you need something else, please elaborate on your requirements. Things like string replacement or regular expression replacement come to mind for more generic problems.

Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55
0

If it comes always end of the string the you can use

substr($string, 0, -3);
Partha Sarathi Ghosh
  • 10,936
  • 20
  • 59
  • 84
0

use str_replace function

$s = "~ All taxes<br/>~ Complimentary Buffet Breakfast,<br/>~ Complimentary Wi-Fi<br/>~ Complimentary Fruit Basket only for Suite Room<br/><br/>Facilities and Services:<br/>~ 24Hrs Room Service<br/>~ Lounge<br/>~ Direct Dialing STD and ISD facilities <br/>Kindly Note:<br/>Before 72Hrs Cancellation full refund";

$new_string =  str_replace('<br/>Kindly Note:<br/>Before 72Hrs Cancellation full refund', '', $s);
Mohammad
  • 3,449
  • 6
  • 48
  • 75
0

Assume "Kindly Note:" exists in the string and you want to remove anything after the "Kindly Note:"

echo strstr($includes, "Kindly Note:", true);
Andrew
  • 2,810
  • 4
  • 18
  • 32