Reputation:
I was wondering how can I turn the echo part into a varialble (I think thats whats you call it) because I can post the "Please enter your last name!" any where on the web page.
// Check for a last name. if (eregi ('^[[:alpha:]\.\' \-]{2,30}$', stripslashes(trim($_POST['last_name'])))) { $ln = escape_data($_POST['last_name']); } else { $ln = FALSE; echo 'Please enter your last name!
'; }
Upvotes: 0
Views: 201
Reputation: 48933
eregi is DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0.
I would recommend to stop using it and use something like preg_match in addition to Gumbo's answer, just change out the use of the eregi function for the preg family
Upvotes: 0
Reputation: 4084
If all you want to do is store that one string in a variable and re-use it, it would be something like this (may not be correct php)
$errorMsg = 'Please enter your last name!';
then wherever you want to use it
echo $errorMsg;
but I recommend doing what the above person said if you have more than one string you wish to re-use.
Upvotes: 0
Reputation: 655239
You could gather the errors in an array and print them later:
$errors = array();
// Check for a last name.
if (eregi ('^[[:alpha:]\.\' \-]{2,30}$', stripslashes(trim($_POST['last_name'])))) {
$ln = escape_data($_POST['last_name']);
} else {
$ln = FALSE;
$errors[] = 'Please enter your last name!'
}
if ($errors) {
echo '<ul>';
echo '<li>'.implode('</li><li>', $errors).'</li>';
echo '</ul>';
} else {
// no errors occured
}
Upvotes: 6