westman Posted July 4, 2012 Share Posted July 4, 2012 hello agin am back how do i remove evey at the end on a url like... http://www.google.co.uk/#hl=en&output=search&sclient=psy-ab&q=cat&oq=cat&gs_l=hp.3..0l4.1417.1966.0.2642.3.3.0.0.0.0.292.699.2-3.3.0...0.0.O5jDmsat_hQ&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&fp=1deb3a27a4d9b1ab&biw=1366&bih=664 will be...http://www.google.co.ukremoving every thing after the /how do i do this? i can remove everything before like... $site_url = str_replace("http://", "", $site_url);$site_url = str_replace("http://www.", "", $site_url);$site_url = str_replace("https://", "", $site_url);$site_url = str_replace("https://www.", "", $site_url);$site_url = str_replace("www.", "", $site_url); but i need to remove everything after the /how? Link to comment Share on other sites More sharing options...
birbal Posted July 4, 2012 Share Posted July 4, 2012 (edited) it can be done in many ways like you can extract the protocol part first (http:// or https://) with the two sslashes. then you can use use strpos() to rest of the string o get the location of first forward slash. then you can use substr() to get partial string using the position of the first slash. http://php.net/strposhttp://php.net/substr or you can use http://php.net/preg_replace preg_replace() Edited July 4, 2012 by birbal Link to comment Share on other sites More sharing options...
westman Posted July 4, 2012 Author Share Posted July 4, 2012 could you povide a code example, that would be helpfull Link to comment Share on other sites More sharing options...
birbal Posted July 5, 2012 Share Posted July 5, 2012 somthing like...(untested)using regExp: echo preg_replace("@http|https|ftp|ftps://[\w\d.]+/(.+)@", '' , $URL); Link to comment Share on other sites More sharing options...
justsomeguy Posted July 5, 2012 Share Posted July 5, 2012 I would use the parse_url function to break the URL into parts and then rebuild it with only the parts you want. http://www.php.net/manual/en/function.parse-url.php Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now