Dostavista Test - 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 Dostavista Test.php

  1. <?php
  2.  
  3. $text = '
  4. Max Verstappen was the closest thing to a challenge to Lewis Hamilton throughout qualifying, the two trading fastest laps for much of a compelling hour of viewing until Hamilton moved into another dimension in the worsening conditions of the closing minutes of the top 10 shoot-out.
  5.  
  6. Verstappen was nearly 0.8secs behind as he headed into his last lap, and he hung it all out there in an attempt to close up. But it took him over the edge. He has already had two enormous moments, through Turn Five and into Six and out of Seven, before he lost it completely through Nine, getting on to the kerb and half-spinning.
  7.  
  8. He admitted the lap was not anyway going to be enough to challenge Hamilton, but he is confident starting the race on the second row of mixing it with the Mercedes for the win. “In the dry I think we can have a good shot at it,” the Dutchman said. “We’ll see how it’s going to go. I think our car, in general, is better than last week’s so I’m looking forward to it.”Max Verstappen was the closest thing to a challenge to Lewis Hamilton throughout qualifying, the two trading fastest laps for much of a compelling hour of viewing until Hamilton moved into another dimension in the worsening conditions of the closing minutes of the top 10 shoot-out.
  9.  
  10. Verstappen was nearly 0.8secs behind as he headed into his last lap, and he hung it all out there in an attempt to close up. But it took him over the edge. He has already had two enormous moments, through Turn Five and into Six and out of Seven, before he lost it completely through Nine, getting on to the kerb and half-spinning.
  11.  
  12. He admitted the lap was not anyway going to be enough to challenge Hamilton, but he is confident starting the race on the second row of mixing it with the Mercedes for the win. “In the dry I think we can have a good shot at it,” the Dutchman said. “We’ll see how it’s going to go. I think our car, in general, is better than last week’s so I’m looking forward to it.”';
  13.  
  14. $french = ' Les Polonais sont appelés aux urnes ce dimanche, pour le second tour de l`élection présidentielle qui oppose le président conservateur sortant Andrzej Duda au maire libéral de Varsovie Rafal Trzaskowski.
  15.  
  16. Les Polonais sont appelés à trancher, dimanche 12 juillet, entre un président conservateur sortant et un libéral europhile qui veut rétablir les liens avec Bruxelles, dans une élection présidentielle dont le second tour s’annonce très serré.  
  17.  
  18. Le résultat de ce scrutin sera décisif pour l`avenir du gouvernement du parti conservateur et nationaliste Droit et Justice (PiS), que ses détracteurs accusent de faire reculer les libertés démocratiques acquises il y a trois décennies à la chute du communisme. 
  19.  
  20. Soutenu par le PiS, le président Andrzej Duda fait face au maire de Varsovie, Rafal Trzaskowski, du principal parti d`opposition centriste Plateforme civique (PO), et les derniers sondages font état de chances égales pour les deux candidats. ';
  21.  
  22. /**
  23.  * В лоб, без Intl будет тяжеловато. Но все что не выходит за границы базового юникода должно считать.
  24.  * Без Intl будет валится на Китайском, например.
  25.  * Если взять во внимание Intl, то есть WordBreakIterator или нечто подобное.
  26.  * Еще есть вариант с регулярками, но он крайне медленный.
  27.  */
  28. function countWords(string $text): array
  29. {
  30.     return array_slice(array_count_values(str_word_count(strtolower($text), 1)), 0, 5);
  31. }
  32.  
  33. # Some edge cases
  34. var_dump(countWords('') === []);
  35. var_dump(count(countWords('test')) === 1);
  36. var_dump(countWords('test Test rest')['test'] === 2);
  37.  
  38. # real words input
  39. var_dump(countWords($text));
  40. var_dump(countWords($french));
  41.  
File Description
  • Dostavista Test
  • PHP Code
  • 12 Jul-2020
  • 3.78 Kb
You can Share it: