<?php class stringGenerator { public function generateRandomString($length = 11) { $valid_chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $charactersLength = strlen($valid_chars); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $valid_chars[rand(0, $charactersLength - 1)]; } return $randomString; } public function displayPage($string) { echo "<!DOCTYPE html>\n\t\t<head>\n\t\t<title>String Generator</title>\n\t\t<meta http-equiv='Content-Type' content='text/html;charset=utf-8'/>\n\t\t<link href='css/styles.css' rel='stylesheet' />\n\t\t</head>\n\t\t<body>\n\t\t\t<div>\n\t\t\t<h1>Here is your random string:</h1>\n\t\t\t\t<form id='unit' method='post' action='index.php'>\n\t\t\t\t<div>{$string}</div>\n\t\t\t\t</form>\n\t\t\t</div>\n\t\t</body>\n\t\t</html>"; } } //remember to use your variable after you return it $stringGenerator = new stringGenerator(); $string = $stringGenerator->generateRandomString(); $stringGenerator->displayPage($string);