Jump to content

Archived

This topic is now archived and is closed to further replies.

BluePhoenixNC

formatting an URL for DB ?

Recommended Posts

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.9

As 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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.