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 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); ?> 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... 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? 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) 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 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).'" />'; } 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) 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
Archived
This topic is now archived and is closed to further replies.