Forum Moderators: coopster

Message Too Old, No Replies

preg_match help

preg_match dynamic URL

         

smagdy

9:12 pm on Apr 15, 2006 (gmt 0)

10+ Year Member



Hello,

Please someone who can use preg_match help me...

i check if the url is write using this

preg_match("/^(http(s?):\\/\\/¦ftp:\\/\\/{1})((\w+\.)+)\w{2,}(\/?)$/i", $url)

but i found that it wont accept dynamic pages with URLs like "?" or "&"

so can u edit it to let it accept those characters and if more needed that is needed for dynamic urls..

Thanks in advance

henry0

10:28 pm on Apr 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use this (part of an online questionnaire)
Note that I concat $pre to add the URL beginning
which is is required but that we do not want an user to type.
at the end + sign requires a non empty form field
and the " i " allows for either upper ot lower case

Hmmm I should remove it.

$site_love= $_POST['site_love']; // echo"site love.$site_love";
$pre="http://";
$site_love_2=$pre.$site_love;
if(!preg_match("/^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i",$site_love_2)) {
Echo"You must supply a valid URL. site you love<br>
<b>$biz_name</b><br>
<a href=\"../n_c/pre_quest.php\">Please try again</a>";
Exit();
}

smagdy

11:01 pm on Apr 15, 2006 (gmt 0)

10+ Year Member



Hi,

Thanks i tried it, but i think it has some flows!

i mean it passed some wrong urls... mine was fine but need to insert just the part of &? =

Thanks