André Cardoso
André Cardoso

Reputation: 115

Help with stripos() and substr()

how do I remove everything before "sentido" in this string:

$string = "#BLitz da #PM na est do pontal sentido prainha perto do camping";

i want the new string to be:

$string = "prainha perto do camping";

I keep failing when I try to do it with stripos and substr, help !

Upvotes: 0

Views: 155

Answers (2)

Wh1T3h4Ck5
Wh1T3h4Ck5

Reputation: 8509

That's another easy way...

$string = "#BLitz da #PM na est do pontal sentido prainha perto do camping";

$s = explode('sentido', $string, 2);
$result = isset($s[1]) ? trim($s[1]) : "";
echo $result;

Output

sentido prainha perto do camping

Upvotes: 0

mario
mario

Reputation: 145482

You can accomplish it without handing any string positions:

$string = strstr(strstr($string, "sentido"), " ");

This will first search for your word, and return the remainder of the string. The second strstr searches for the space afterwards, and returns the rest from there.

Upvotes: 3

Related Questions