I have a fairly straightforward piece of code
<div id="questdiv">
<?php
$a = rand() % 100;
$b = rand() % 100;
print "What is ";
print (string)$a;
print " + ";
print (string)$b;
print "?";
?>
</div>
and yet the text that appears in my div is
What is "; print (string)$a; print " + "; print (string)$b; print "?
"; ?>
What have I done wrong? I tried replacing print
with echo
and that did the same thing.
Your file is obviously not saved as .php file.
Probably your file is called something like this:
index.html
index.htm
change it into
xxx.php
Aswell you need a Server for your PHP, to work.
Check following website, to setup your own local server and make your PHP work: https://www.apachefriends.org/en/index.html
you should try
<div id="questdiv">
<?php
$a = rand(0,100);
$b = rand(0,100);
echo "what is ".$a." + ".$b."?";
?>
</div>
And check if extension is .php (file) + if server supports PHP
Btw this is the short version of your code so try using this way ;)