Forum Moderators: coopster

Message Too Old, No Replies

preg match fatal error.

         

ahmedtheking

8:20 pm on Aug 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I get this error when using preg_match:

Fatal error: Can't use function return value in write context in /Applications/xampp/htdocs/sites/cmyk/signup.php on line 14

Here's the code (starts at line 2):


// if post info sent
if (!empty($_POST)) {
// set arrays
$errorclass = array();
$errornote = array();

// check post info
foreach ($_POST as $k => $v) {
if (stristr($k,"email") ¦¦ stristr($k,"password") ¦¦ stristr($k,"postcode")) {
// check for basic alpha numeric entry
if (!preg_match("/[0-9A-Za-z\s\-]+/",$v)) {
// error
$errorclass($k) = " class=\"error\"";
$errornote($k) = "Invalid ".ucwords(
str_replace(
array("name","number"),
array(" name"," number"),
$k)
);

} else {
// format data
$postdata[$k] = ucwords($v);

}
}
}

pinterface

12:29 am on Aug 12, 2006 (gmt 0)

10+ Year Member



Your problem is not the preg_replace, it's:

$errorclass($k) = " class=\"error\"";
$errornote($k) = "Invalid ".ucwords(

$foo($k) is a function call; as the error message is trying to tell you, assignment to a function call makes no sense.

You probably want square brackets to access an array index:


$errorclass[$k] = " class=\"error\"";
$errornote[$k] = "Invalid ".ucwords(

ahmedtheking

11:04 am on Aug 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah figured it out, sorry!