BluePhoenixNC Posted May 23, 2006 Share Posted May 23, 2006 Ok, here is my problem and I am not very much familiar with either "ereg_replace or preg-match".What I am trying to do: I have a form where the visitor can enter a URL to their Website.Since I do not know what they will type in (http://domain.com/index.~) I want to get rid of the (http://) so I can save it to the DB as "domain.com/~whatever" or if the user typed in www.domain.com I would like to save that..all without the (http://) - so I have everything uniform in the table and can then use it later if needed as a working url by simply adding the http:// prefix. Does that make any sense ? (And no, I am not running into people putting https:// or ftp:// into the field)Maybe I should also mention that I use php 4.3.9As always thank you in advance for all your help, if this question had already been asked (an I am to stupid to find it, my apologies, please point me then to the link.... I am searching now for days for a solution) Quote Link to comment https://forums.phpfreaks.com/topic/10273-formatting-an-url-for-db/ Share on other sites More sharing options...
ober Posted May 23, 2006 Share Posted May 23, 2006 You could do something even more simple:[code]if(substr($url,0,7) == 'http://')$url = substr($url, 7));[/code]I always screw up the math on that second part, so you might want to test it. Quote Link to comment https://forums.phpfreaks.com/topic/10273-formatting-an-url-for-db/#findComment-38356 Share on other sites More sharing options...
BluePhoenixNC Posted May 23, 2006 Author Share Posted May 23, 2006 [!--quoteo(post=376451:date=May 23 2006, 03:35 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 23 2006, 03:35 PM) [snapback]376451[/snapback][/div][div class=\'quotemain\'][!--quotec--]You could do something even more simple:[code]if(substr($url,0,7) == 'http://')$url = substr($url, 7));[/code]I always screw up the math on that second part, so you might want to test it.[/quote]That was exactly what I was looking for..... Thank you very much and the math works, too.... ;) put the {} around the $url= and voila.... Awesome..... Again thank you, Ober Quote Link to comment https://forums.phpfreaks.com/topic/10273-formatting-an-url-for-db/#findComment-38368 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.