I have looked through some of the other questions on here about including variables from another php file but I've had no luck.
I am trying to include the return of a function in my <title></title>
randomtitle.php
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
Here is my index.php
index.php
<!DOCTYPE html>
<html>
<head>
<?php require_once('randomtitle.php'); ?>
<title><?php echo generateRandomString(); ?></title>
</head>
<body>
</body>
</html>
I get a fatal error Call to undefined function generateRandomString()
. Also the actual randomtitle.php file gets displayed in the body of my index.php.