The Little Guy Posted August 6, 2009 Share Posted August 6, 2009 is there a php funciton that will take something like this: For command line: /home/ryannaddy/phpsnips.com/images/s/image_name.jpg and convert it to something that looks like this: For Web: /images/s/image_name.jpg Quote Link to comment https://forums.phpfreaks.com/topic/169152-solved-is-there-a-function-to/ Share on other sites More sharing options...
jonsjava Posted August 6, 2009 Share Posted August 6, 2009 str_replace <?php $url = "home/ryannaddy/phpsnips.com/images/s/image_name.jpg"; str_replace("/home/rayannaddy/phpsnips.com","",$url); ?> Quote Link to comment https://forums.phpfreaks.com/topic/169152-solved-is-there-a-function-to/#findComment-892514 Share on other sites More sharing options...
The Little Guy Posted August 6, 2009 Author Share Posted August 6, 2009 no... I need to distribute the code, so that isn't going to work... Quote Link to comment https://forums.phpfreaks.com/topic/169152-solved-is-there-a-function-to/#findComment-892515 Share on other sites More sharing options...
jonsjava Posted August 6, 2009 Share Posted August 6, 2009 I was taking a guess. You were kinda vague. Please explain further. You mean take the working directory and remove everything up to the web directory? Quote Link to comment https://forums.phpfreaks.com/topic/169152-solved-is-there-a-function-to/#findComment-892516 Share on other sites More sharing options...
mikesta707 Posted August 6, 2009 Share Posted August 6, 2009 you will probably want to look into some regex functions, like preg_replace. I'm not to good with regex (and there is another subforum dedicated to regex problems) Quote Link to comment https://forums.phpfreaks.com/topic/169152-solved-is-there-a-function-to/#findComment-892517 Share on other sites More sharing options...
kickstart Posted August 6, 2009 Share Posted August 6, 2009 Hi If you want to find that section of the name then you will probably need to play around with various server variables:- http://us3.php.net/manual/en/reserved.variables.server.php All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/169152-solved-is-there-a-function-to/#findComment-892519 Share on other sites More sharing options...
The Little Guy Posted August 6, 2009 Author Share Posted August 6, 2009 You mean take the working directory and remove everything up to the web directory? yeah, I believe so... I would like to do this: $smalDir = $_SERVER['DOCUMENT_ROOT'].'/images/s/'; /* ~ 27 other lines of unrelated code */ foreach(glob($smalDir.'*') as $img){ echo '<img src="'.someFunction($img).'" />'; } Quote Link to comment https://forums.phpfreaks.com/topic/169152-solved-is-there-a-function-to/#findComment-892524 Share on other sites More sharing options...
The Little Guy Posted August 6, 2009 Author Share Posted August 6, 2009 str_replace <?php $url = "home/ryannaddy/phpsnips.com/images/s/image_name.jpg"; str_replace("/home/rayannaddy/phpsnips.com","",$url); ?> I used that, just changed it to: str_replace($_SERVER['DOCUMENT_ROOT'], '',$img) Quote Link to comment https://forums.phpfreaks.com/topic/169152-solved-is-there-a-function-to/#findComment-892536 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.