unemployment Posted April 17, 2011 Share Posted April 17, 2011 How can I make the image path not have the starting slash for the $path? Currently this... function getUserAvatar($username) { if (file_exists("{$GLOBALS['path']}/img/${username}.png")) { return "/assets/img/${username}.png"; } else { return "/assets/img/defaultuser.jpg"; } } When path is executed I need it to make /assets/ be assets/ I need to remove the first character from the $path variable. if ($type === 'image/png'){ imagepng($this->img, $path); } Quote Link to comment https://forums.phpfreaks.com/topic/233937-image-path-question/ Share on other sites More sharing options...
joel24 Posted April 17, 2011 Share Posted April 17, 2011 substr() $variable = "/assets/img/defaultuser.jpg"; $variable = substr($variable, 1); Quote Link to comment https://forums.phpfreaks.com/topic/233937-image-path-question/#findComment-1202474 Share on other sites More sharing options...
.josh Posted April 17, 2011 Share Posted April 17, 2011 ltrim using the 2nd argument would be better, as it will remove it only if it exists. $string = ltrim($string,'/'); Quote Link to comment https://forums.phpfreaks.com/topic/233937-image-path-question/#findComment-1202475 Share on other sites More sharing options...
QuickOldCar Posted April 17, 2011 Share Posted April 17, 2011 or ltrim <?php $var ="/assets/img/defaultuser.jpg"; $var = ltrim($var, '/'); echo $var; ?> beat me to it Quote Link to comment https://forums.phpfreaks.com/topic/233937-image-path-question/#findComment-1202476 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.