Jump to content


Photo

formatting an URL for DB ?


  • Please log in to reply
2 replies to this topic

#1 BluePhoenixNC

BluePhoenixNC
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 23 May 2006 - 03:20 PM

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)

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 23 May 2006 - 07:35 PM

You could do something even more simple:
if(substr($url,0,7) == 'http://')
$url = substr($url, 7));

I always screw up the math on that second part, so you might want to test it.

Info: PHP Manual


#3 BluePhoenixNC

BluePhoenixNC
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 23 May 2006 - 08:03 PM

[!--quoteo(post=376451:date=May 23 2006, 03:35 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 23 2006, 03:35 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You could do something even more simple:
if(substr($url,0,7) == 'http://')
$url = substr($url, 7));

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users