Jump to content

If no protocol?


Azu

Recommended Posts

Hello I'm working on making a regex for URL links since none of the ones I've found work right for me.

 

I just have one little problem with it.. I can't figure out how to make it give http:// as the default protocol if there is no protocol given.

 

Like with the URL www.google.com/search?q=Foo

 

And since I don't know how to make it add one, clicking on the link ends up taking you to http://MyWebsite.com/www.google.com/search?q=Foo

Instead of http://www.google.com/search?q=Foo

 

So please tell me how to do this in regex..

 

 

 

In PHP I would do it somewhat like this

if(substr($Blah,0,4)=='http')$Foo='http';
elseif(substr($Blah,0,3)=='ftp')$Foo='ftp';
//etc
else$Foo='http';

 

 

Edit: the way I have it in regex right now is like

(https?|ftp)

Anyways ya basically I want that to return "http" if it doesn't match https? or ftp.

Link to comment
https://forums.phpfreaks.com/topic/74426-if-no-protocol/
Share on other sites

Archived

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

×
×
  • 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.