我有一个句子,我想随机隐藏一个单词,例如:
<?php
$sentence = 'My name is Abu Rayane';
?>
如何继续隐藏该句子中的单词并将其替换为输入文本,以便用户可以填写它,然后检查它是否正确?例如:
My name is Abu <input type="text" name="fillBlank"> <br />
<input type="submit" name="check" value="check">
最佳答案
$sentence = 'My name is Abu Rayane';
$sentence = explode(' ', $sentence);
$position = rand(0, count($sentence) - 1);
$answer = $sentence[$position];
$sentence[$position] = '<input type="text" name="fillBlank">';
echo implode(" ", $sentence);
编辑:如果单词长度未知,则使其工作
关于php - 从句子中随机隐藏单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25584753/