Eduardo Rafael
Eduardo Rafael

Reputation: 81

Delete string to the right in PHP

The below code deletes to the left and not to the right.

Actual code:

$citygen=substr($citygen,strrpos($citygen,'&fbclid='));

Example:

?geo&moyobamba&fbclid=fdfdsfddsfds4324

I need to delete to the right from &fbclick= (since sometimes these numbers change)

Upvotes: 1

Views: 61

Answers (1)

Nick
Nick

Reputation: 147206

You're missing the $start parameter to substr, so it is fetching characters from the location of &fblcid onwards. Try this instead:

$citygen = '?geo&moyobamba&fbclid=fdfdsfddsfds4324';
$citygen = substr($citygen,0,strrpos($citygen,'&fbclid='));
echo $citygen;

Output:

?geo&moyobamba

Demo on 3v4l.org

Upvotes: 3

Related Questions