sx Posted March 20, 2007 Share Posted March 20, 2007 I tried to find this and I tried to get it to work with truncate but no luck. What I want to do is remove some of a url. The host and lenth of the length may vary greatly too depending on who is posting the link. The host can be anyone. Say I have this url http://rapidshare.com/files/9839432/asdf/sadf/asd/fasd/fTiger_Army.rar I want it to change to http://rapidshare.com/.../fTiger_Army.rar Or this one http://i11.tinypic.com/hello/485awkj.jpg It should show up as http://i11.tinypic.com/.../485awkj.jpg Link to comment https://forums.phpfreaks.com/topic/43502-truncating-a-url/ Share on other sites More sharing options...
trq Posted March 20, 2007 Share Posted March 20, 2007 Take a look at parse_url(). Link to comment https://forums.phpfreaks.com/topic/43502-truncating-a-url/#findComment-211244 Share on other sites More sharing options...
sx Posted March 20, 2007 Author Share Posted March 20, 2007 Ok. That was kewl thank you. I got it to seperate the host from the rest. That was kewl. Now What I want to do is start counting from the RIGHT back about 20 characters and then remove everything before that point and leave everything after it.. So this /files/9839432/asdf/sadf/asd/fasd/fTiger_Army.rar Should become ...sd/fTiger_Army.rar Here is what I did so far only it doesn't work right. It removes everything AFTER that point. function truncate ($string, $max = 20, $rep = '') { $leave = $max - strlen ($rep); return substr_replace($string, $rep, $leave); } $url = 'http://rapidshare.com/files/9839432/asdf/sadf/asd/fasd/fTiger_Army.rar'; print_r(parse_url($url)); $home = parse_url($url, PHP_URL_PATH); $home = truncate ($home, '-6', '...' ); echo "<br><br><br>"; echo "$home"; Link to comment https://forums.phpfreaks.com/topic/43502-truncating-a-url/#findComment-211317 Share on other sites More sharing options...
per1os Posted March 20, 2007 Share Posted March 20, 2007 http://us2.php.net/manual/en/function.substr.php Substr seems to be your next step. Link to comment https://forums.phpfreaks.com/topic/43502-truncating-a-url/#findComment-211323 Share on other sites More sharing options...
sx Posted March 21, 2007 Author Share Posted March 21, 2007 That got it. Thanks. Link to comment https://forums.phpfreaks.com/topic/43502-truncating-a-url/#findComment-212105 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.