MyBB Community Forums

Full Version: PHP help please
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Guys please help I am trying to create a plugin and I need you to help me to make this code work with url without www

$regex = "%\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))%s";
The better regular expression should be:

/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/

Thanks to Mathew.
http://blog.mattheworiordan.com/post/131...ithout-the
How to only mach http:// https:// and www
For http:// or https:// this is good enough:

^https?://

but you can throw the check separately as well:

^(http|https)://

hence, as per your query:

$regex = "(http|https)://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?";

and by this you can handle any or every protocol:

$regex = "([a-zA-Z]{3,})://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?";
Thanks very much but I have a problem for some reason non of the codes work except this one what seem to be the issue?

$regex = "%\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))%s";


This code matches domain.tld but how do I make it also match http:// and www
$regex = "%\b(.*([\w-]+\.)+[a-z]{2,5}(/[\w-]+)*)%s";

Looks like I nailed it can anybody check me please??????????
$regex = "%\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))|(.*([\w-]+\.)+[a-z]{2,5}(/[\w-]+)*)%s";