pneudralics Posted November 14, 2008 Share Posted November 14, 2008 I have a string that has a value of: http://blahblah.com/folder/image.jpg I want to take everything out except for the image.jpg. The image have different names so I want to start with / and delete everything forward of that. Just need some help on accomplishing this. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/132724-solved-need-some-help-with-string-replacement/ Share on other sites More sharing options...
Mark Baker Posted November 14, 2008 Share Posted November 14, 2008 <?php $url = 'http://blahblah.com/folder/image.jpg'; $parsed = pathinfo($url); echo $parsed['basename']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/132724-solved-need-some-help-with-string-replacement/#findComment-690222 Share on other sites More sharing options...
thebadbad Posted November 14, 2008 Share Posted November 14, 2008 <?php $str = 'http://blahblah.com/folder/image.jpg'; $str = substr($str, 0, strrpos($str, '/') + 1); ?> Quote Link to comment https://forums.phpfreaks.com/topic/132724-solved-need-some-help-with-string-replacement/#findComment-690226 Share on other sites More sharing options...
pneudralics Posted November 14, 2008 Author Share Posted November 14, 2008 <?php $url = 'http://blahblah.com/folder/image.jpg'; $parsed = pathinfo($url); echo $parsed['basename']; ?> Thanks got it working but it also echoes Array after the image name? Quote Link to comment https://forums.phpfreaks.com/topic/132724-solved-need-some-help-with-string-replacement/#findComment-690246 Share on other sites More sharing options...
Mark Baker Posted November 14, 2008 Share Posted November 14, 2008 Thanks got it working but it also echoes Array after the image name? Are you trying to echo $parsed anywhere? Quote Link to comment https://forums.phpfreaks.com/topic/132724-solved-need-some-help-with-string-replacement/#findComment-690250 Share on other sites More sharing options...
pneudralics Posted November 14, 2008 Author Share Posted November 14, 2008 Got it to work. Thanks. I was just echoing to see what the string was. echo(pathinfo("mystring",PATHINFO_BASENAME)); Quote Link to comment https://forums.phpfreaks.com/topic/132724-solved-need-some-help-with-string-replacement/#findComment-690259 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.