重新加载页面后如何更改单词

How make words change after reload pages

我想在用户重新加载网站后更改文字

$words = ["Bonjourr", "Holaa", "Hi! Mister", "Hello World", "Nice!"];
$word_count  = count($words);
$selected_number = rand(0, ($word_count-1)); 
$selected_word = $words[$selected_number];
echo "{$selected_word}";

让我们试试这个

服务器端单词生成器不是最好的主意。请改用客户端。 您可以使用服务器获取单词列表或它们的任何其他来源。 以下是您项目的两个示例:

  • 第一个基于单词数组作为来源
  • 第二个基于字符串

// 1. Array
var words = ['One', 'Morning', 'Star'];

// 2. String
var text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum euismod nisl a malesuada laoreet. Vivamus consequat, mi vel fermentum ultricies, dui libero ullamcorper velit, eu hendrerit lacus lorem a lacus. Suspendisse id diam quam. In tristique risus non turpis feugiat sagittis. Nam vitae turpis tincidunt leo faucibus ultrices. Suspendisse tristique pharetra ante, sit amet luctus odio. Pellentesque libero tortor, lacinia in mattis ut, ullamcorper a enim. Donec gravida, neque eget lacinia porta, quam ex rhoncus sem, ac semper ligula lacus non ligula. Vivamus id risus convallis, rhoncus nisi et, efficitur magna. In sit amet dolor ut dui accumsan dignissim. Curabitur lobortis nisi eu sapien accumsan luctus. Nullam blandit turpis ut massa ultricies cursus.";

var wordFromArr = words[Math.floor(Math.random() * words.length)];
var wordFromString = text.split(" ")[Math.floor(Math.random() * words.length)];

document.getElementById("output").innerText = wordFromArr;
<div id="output"></div>