Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

How to generate random sentence consisted of random words with PHP

Posted on July 18, 2019August 4, 2020 by Habibie

In this post I’m going to share a simple PHP script to generate random sentence consisted of random pre-defined words.

For example I want to show a text saying: “Hi, thank you for visiting my website” several times, but I don’t want repetitively saying exactly that sentence. Then the solution is this program, which can randomize some of words in this sentence so somehow it uniquely showing different sentences with same meaning.

To see the example please watch this video:

Here is the code:

<?php

$word1 = array("Hi", "Hello");
$word2 = array("thank you", "thanks", "thanks very much");
$word3 = array("visiting", "opening", "browsing");
$word4 = array("my website", "this website", "this blog");

function randomize($word){
	return $word[rand(0, count($word)-1)];
}

echo randomize($word1) . ", " . randomize($word2) . " for " . randomize($word3) . " " . randomize($word4) . ".";

?>
Post Views: 227
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
  • Advanced Blinking Marker Script to show objects position in your game canvas
  • Ciihuy Images Merger – Fast & Easy Online Image Combiner
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme