Jump to content

ereg() - error: function name must be a string


PC Nerd

Recommended Posts

Hi,

 

Im working on a validation script for creating user accounts - and Im not at all familiar with ereg(), preg_match() etc.  Ive been mashing together expressions from forums etc - and Ive come accrose the error with the following line:

 

if(!ereg("[A-za-z' -]{1, 50}", $trim($value))) {

 

Here is the surounding code:

 

...
...
foreach($_POST as $field => $value) {
	if($_POST['Save'] == 1 && $field == "User_Name" || $field == "Password" || $field == "Conf_Password" || $field == "Email" || $field == "Emg_Relation") {
		### Validate the Username, password and email
		if(!ereg("[A-za-z' -]{1, 50}", $trim($value))) {
			$ERROR[$idx]['err'] = "invalid";
			$ERROR[$idx]['empty'] = $field;
			$idx ++;
		}
		if(strlen($value) > 20) {
...
...

 

 

The error is this:

 

Fatal error: Function name must be a string in ###\new_user.php on line 60

 

Im confused by the meaning of this error - meaning  ihave no clue as how to fix it. Any suggestions or answers woudl be much appreciated.

 

Thanks in advance

 

A function cannot have a $ in front of the name.

 

<?php
$trim($value)

 

needs to be

<?php
trim($value)

 

PhREEEk

 

It can, but only if the variable contains the name of a valid function.

 

E.g.

$func = 'print';
$arg = 'test';

$func($arg);

will output test.

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.