Sven Generator - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of Sven Generator.php

  1. <?php
  2.  
  3. class Sven {
  4.     
  5.     public function isTrue() {
  6.         return false;
  7.     }
  8.     
  9.     public function genereteAnswer() {
  10.         $phrases = array(
  11.             'I am',
  12.             'bitch',
  13.             'do',
  14.             'you',
  15.             'have',
  16.             'any',
  17.             'news',
  18.             'for',
  19.             'me'
  20.           );
  21.  
  22.         $answer = '';
  23.         $count = rand(1, 8);
  24.         for($i = 1; $i < $count; $i++) {
  25.             $answer .= $phrases[array_rand($phrases)];
  26.             if($i + 1 != $count)
  27.                 $answer .= ' ';
  28.         }
  29.         $answer .= rand(0,1) %2 == 0 ? '?' : '!';
  30.  
  31.         return ucfirst($answer);
  32.     }
  33. }
  34.  
  35. $superman = new Sven();
  36.  
  37. echo '<strong>Q:</strong> Hi Sven, do you have a minute?' . "\n";
  38. echo '<strong>A:</strong> ' . ($superman->isTrue() ? 'How can I help you' : $superman->genereteAnswer());
File Description
  • Sven Generator
  • PHP Code
  • 20 Jun-2018
  • 852 Bytes
You can Share it: