rajaboys Posted April 2, 2009 Share Posted April 2, 2009 I have stored db URL like this ../../images/aprilfoolcards/lovefoolsday.gif, ../../images/navratri/navratri1.gif want to know how to get category like aprilfoolcards, navratri in PHP. Regards Raja Quote Link to comment https://forums.phpfreaks.com/topic/152233-php-substring/ Share on other sites More sharing options...
MadTechie Posted April 2, 2009 Share Posted April 2, 2009 basically you use strrpos and substr ie <?php $path = "../../images/aprilfoolcards/lovefoolsday.gif"; $cat = substr($path, 13, strrpos($path,"/", 13)-13); echo $cat; ?> untested EDIT updated: made a pigs ear of that! Quote Link to comment https://forums.phpfreaks.com/topic/152233-php-substring/#findComment-799405 Share on other sites More sharing options...
sasa Posted April 2, 2009 Share Posted April 2, 2009 explode on / and get one before last $x = ekplode('/', $url); $part = $x[count($x)-2]; Quote Link to comment https://forums.phpfreaks.com/topic/152233-php-substring/#findComment-799420 Share on other sites More sharing options...
MadTechie Posted April 2, 2009 Share Posted April 2, 2009 Which is easier than using a substr also sasa code should be $x = explode('/', $url); not $x = ekplode('/', $url); Quote Link to comment https://forums.phpfreaks.com/topic/152233-php-substring/#findComment-799436 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.