Jump to content

formatting an URL for DB ?


BluePhoenixNC

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.