Jump to content

Remove Characters After Nth Occurence Of Symbol


matthewtbaker

Recommended Posts

Good day!

 

I've tried a few routes but haven't managed a simple approach. Ideally I'd like to use one of PHPs built in functions to make the code cleaner and easier to follow.

 

Basically I need to remove anything after a defined number of occurrences of a character from the example string below;

 

 

$iLevels = 2;

$sUrl = http://www.example.com/products/entertainment/films/dvd/page.html

 

So in this case I need to remove anything after the second to last forward slash, deleting dvd/page.html. The number of forward slashes to remove is variable therefore a flexible solution is needed.

 

Thanks for your help/advice in advance!

 

Matt

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.