fork(3) download
  1. <?php
  2. $error = false;
  3. $original_value = 'hello world 進撃進撃 lorem ipsum';
  4. $originalLenght = strlen($original_value); // get the string length
  5. $parts = explode(" ", $original_value);
  6.  
  7.  
  8. $newValue = "hello world newword";
  9. $newLenght = strlen($newValue); // get the new string length
  10. $newParts = explode(" ", $newValue);
  11.  
  12. //Check if the new sentence contains new words using in_array
  13. foreach($newParts as $newWord){
  14. if (!in_array($newWord, $parts)) {
  15. $error = true;
  16. }
  17. }
  18.  
  19. //Check if the size of the new sentence is > than the original
  20. if($newLenght > $originalLenght OR $error){
  21. echo "Invalid Sentence";
  22. }else{
  23. echo "Valid Sentence";
  24. }
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Invalid Sentence