Jump to content

URL editing


westman

Recommended Posts

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

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 by birbal
Link to comment
Share on other sites

somthing like...(untested)using regExp:

 echo preg_replace("@http|https|ftp|ftps://[\w\d.]+/(.+)@", '' , $URL);

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...