Web Hosting Talk







View Full Version : php function error (error: Unknown Modifier) help to resolve it plz


latheesan
06-30-2005, 07:26 PM
hey everyone,

I've been recently working on a registeration script, written in php. Im finished and currently de-bugging the script.

on registeration form, user has the option to enter their website. so in my register.php file, i've made a function that chnages the wronly written web url into correct form. e.g, htp:/ to http://. Anyway, when the script is in use, i keep getting this error:

Warning: preg_match() [function.preg-match]: Unknown modifier '(' in root\htdocs\members\register.php on line 52

the error is caused by these lines of code in my register.php file

if ($_POST['website'] != '' & !preg_match("/^(http|ftp):///", $_POST['website'])) {
$_POST['website'] = 'http://'.$_POST['website'];

Could anyone please help me debug this code?

Many thanks in advance for any help anyone can offer

latheesan
06-30-2005, 08:07 PM
anyone plz?

psihost
06-30-2005, 08:16 PM
Taking a stab in the dark - have you tried enclosing the http|ftp in square brackets ?

Azavia
06-30-2005, 08:26 PM
Change the line to this, and see if it works

if ($_POST['website'] != '' && !preg_match("/^(http|ftp):\\/\\//", $_POST['website'])) {

aixagent
06-30-2005, 08:27 PM
Originally posted by latheesan
hey everyone,

I've been recently working on a registeration script, written in php. Im finished and currently de-bugging the script.

on registeration form, user has the option to enter their website. so in my register.php file, i've made a function that chnages the wronly written web url into correct form. e.g, htp:/ to http://. Anyway, when the script is in use, i keep getting this error:



the error is caused by these lines of code in my register.php file

if ($_POST['website'] != '' & !preg_match("/^(http|ftp):///", $_POST['website'])) {
$_POST['website'] = 'http://'.$_POST['website'];

Could anyone please help me debug this code?

Many thanks in advance for any help anyone can offer

Easy. You're not escaping the forward slashes.



<?php
$website = $_GET['website'];

if($website)
{
if(!preg_match("/^(http|ftp):\/\//", $website))
{
$website = "http://".$website;
}

echo $website."<br>";
}
?>



Okay the backslashes aren't showing up, it should be:

/ ^ (http|ftp): \ / \ / /

without the spaces of course

Azavia
06-30-2005, 08:30 PM
Yeah aixagent, same happened here, doubling the backslashes makes it display ok. :)

latheesan
06-30-2005, 09:00 PM
i salute you guys. Thanks for all your help.

:D:D:D:D

/ ^ (http|ftp): \ / \ / / <<<<<<<<< this worked great :D