[FIXED] O'Brien
Posted: Sun Jan 25, 2009 9:51 pm
How to sanitise a name such as O'Brien and be able to show it back on the form without being shown as O\'Brien?
The $html array element is the one that will be shown again if the form is not completed properly.
Code: Select all
<?php
function html_prepare($html) {
trim(htmlentities($html, ENT_QUOTES));
return $html;
}
function validate_name($input)
{
$pattern = "/^[\' a-z]{2,20}$/i";
return (bool)preg_match($pattern, $input, $matches);
}
if (validate_name($_POST['name']) == false) {
$error['missing']['name'] = 'Name seems to be invalid';
$html['name'] = html_prepare(ucwords(strtolower($_POST['name'])));
} else {
$clean['name'] = trim(ucwords(strtolower($_POST['name'])));
$html['name'] = html_prepare($clean['name']);
}
?>