Home > Enterprise >  How to remove the last part of a string url in PHP
How to remove the last part of a string url in PHP

Time:10-01

I need to parse a google sheet url string in php, removing the last part of it. Example:

$string = https://docs.google.com/spreadsheets/d/xxxx/edit#gid=xxxxxxx

Then i need to remove the 'edit#gid=xxxxxxx' part of the string, like so:

$string_parsed = https://docs.google.com/spreadsheets/d/xxxx/

CodePudding user response:

Try this: $string_parsed = explode('/','https://docs.google.com/spreadsheets/d/xxxx/edit#gid=xxxxxxx'); array_pop($string_parsed); echo implode('/', $string_parsed);

  • Related