* This function cleans a string, then calls a function with * the string as a parameter. * * See that strange keyword in front of $callback? This is called a "type hint". * It means that whatever is passed in as that parameter must be a function. * * Can you implement this function? */ function clean_then_call($string, callable $callback) { // Use the string cleaning procedure we came up with in exercise 1 on $string // return the result of the $callback function with $string passed in as a parameter } ?> <!DOCTYPE html> <html> <head></head> <body> <p> <?php // MD5 is a hashing algorithm that is commonly used to store passwords echo clean_then_call(' jAsOn hUnTeR', 'md5'); ?> </p> <p> <?php // Write your own using clean_then_call and a closure to manipulate the string further ?> </p> </body> </html>
* * Can you implement this function? */ function clean_then_call($string, callable $callback) { // Use the string cleaning procedure we came up with in exercise 1 on $string // return the result of the $callback function with $string passed in as a parameter $mod_string = ""; $mod_string = ucwords(strtolower(trim($string))); dd($mod_string); return $callback($mod_string); } ?> <!DOCTYPE html> <html> <head></head> <body> <p> <?php // MD5 is a hashing algorithm that is commonly used to store passwords echo clean_then_call(' jAsOn hUnTeR', 'md5'); ?> </p> <p> <?php // Write your own using clean_then_call and a closure to manipulate the string further echo clean_then_call("G0rdon FreeMAN", "md5"); ?> </p> </body> </html>
{ // Use the string cleaning procedure we came up with in exercise 1 on $string $string = ucwords(strtolower(trim($string))); return $callback($string); // return the result of the $callback function with $string passed in as a parameter } ?> <!DOCTYPE html> <html> <head></head> <body> <p> <?php // MD5 is a hashing algorithm that is commonly used to store passwords // echo clean_then_call(' jAsOn hUnTeR', 'md5') . '<br />'; ?> </p> <p> <?php echo clean_then_call('Chuck Pavlick', function ($name) { //uses closure, a function w/ no name for one time use $name = strtoupper($name); //customizes what function does $name = strrev($name); return $name; //saves data }); ?> </p> </body> </html>
function clean_then_call($string, callable $callback) { // Use the string cleaning procedure we came up with in exercise 1 on $string $string = ucwords(strtolower(trim($string))); //Sanitize name // return the result of the $callback function with $string passed in as a parameter return $callback($string); } ?> <!DOCTYPE html> <html> <head></head> <body> <p> <?php // MD5 is a hashing algorithm that is commonly used to store passwords echo clean_then_call(' jAsOn hUnTeR', 'md5'); ?> </p> <p> <?php // Write your own using clean_then_call and a closure to manipulate the string further $cleaned = clean_then_call("JaCOb fOArD", function ($name) { $lenth = strlen($name); return "{$name} - {$lenth}"; }); echo $cleaned; ?> </p> </body> </html>