Monday, February 28, 2011

Create-new-function-PHP (Part 4)

Assalamu'alaikum and selamat sejahtera

For this post,we will learn on how to create a new function that can detect the space or blank space from application.Well,we already learn the trim() but for this function,we want to display some error message if the user did not put anything but still press the submit button.Here is the example:


<?PHP
$user_input = trim("Ali Abu ");
detect_blank($user_input);
function detect_blank($user_input) {
if ($user_input == "") {
print "Sorry,you forget to fill the textbox";
}
else {
print "The form is OK";
}
}

?>

ok,you run it..it print "The form is OK" ryte?so how about change this line,just assuming that $user_input is get the value from the form/application that fill by the user.So change this line:


$user_input = trim("Ali Abu ");
to this:


$user_input = trim("");
so,it print "Sorry,you forget to fill the textbox" ryte?

that's all for today!adios!

N/NOTE:new function for this hectic morning!

1 comment: