@underbottom/

yodashuffler

PHP (Legacy)

No description

fork
loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.20982814223343227","path":"main.php","file":{"path":"main.php","content":{"asEncoding":{"base64":"PD9waHAKIAplcnJvcl9yZXBvcnRpbmcoLTEpOwptYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKIAokdGV4dCA9ICLQmtCw0LbQtdGC0YHRjywg0L3QsNGBINC+0LHQvdCw0YDRg9C20LjQu9C4ISDQndCw0LTQviDRgdGA0L7Rh9C90L4g0YPRhdC+0LTQuNGC0Ywg0L7RgtGB0Y7QtNCwLCDQv9C+0LrQsCDQvdC1INC/0L7Qt9C00L3Qvi4g0JHQtdC20LjQvCDQttC1INGB0LrQvtGA0LXQtSEiOwovLyDQlNGA0YPQs9C40LUg0LLQsNGA0LjQsNC90YLRiyDQtNC70Y8g0YLQtdGB0YLQvtCyCiR0ZXh0MSA9ICLQndGDLCDQv9GA0L7RgdGC0Lgg0LzQtdC90Y8hINCd0LUg0YXQvtGC0LXQu9CwINGPINGC0LXQsdC1INC30LvQsCDRgdC00LXQu9Cw0YLRjDsg0LTQsCDQsiDRgdC10LHQtSDQvdC1INCy0L7Qu9GM0L3QsCDQsdGL0LvQsC4g0KfRgtC+INCz0L7QstC+0YDQuNC70LAsINGH0YLQviDQtNC10LvQsNC70LAsINGB0LXQsdGPINC90LUg0L/QvtC80L3QuNC70LAuIjsKJHRleHQyID0gItCY0LTQtdGCINCz0YDQsNC20LTQsNC90YHQutCw0Y8g0LLQvtC50L3QsC4g0JrQvtGB0LzQuNGH0LXRgdC60LjQtSDQutC+0YDQsNCx0LvQuCDQv9C+0LLRgdGC0LDQvdGG0LXQsiwg0L3QsNC90L7RgdGP0YnQuNC1INGD0LTQsNGAINGBINGC0LDQudC90L7QuSDQsdCw0LfRiywg0L7QtNC10YDQttCw0LvQuCDQv9C10YDQstGD0Y4g0L/QvtCx0LXQtNGDLCDQsiDRgdGF0LLQsN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00LAg0LPQvtCy0L7RgNC40YI6IHskeW9kYVRleHR9XG4tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tXG4iOwoKJHlvZGFUZXh0ID0gbWFrZVlvZGFTdHlsZVRleHQoJHRleHQxKTsKJHlvZGFUZXh0ID0gZml4VGV4dCAoJHlvZGFUZXh0KTsKZWNobyAi0JnQvtC00LAg0LPQvtCy0L7RgNC40YI6IHskeW9kYVRleHR9XG4tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tXG4iOwoKJHlvZGFUZXh0ID0gbWFrZVlvZGFTdHlsZVRleHQoJHRleHQyKTsKJHlvZGFUZXh0ID0gZml4VGV4dCAoJHlvZGFUZXh0KTsKZWNobyAi0JnQvtC00LAg0LPQvtCy0L7RgNC40YI6IHskeW9kYVRleHR9XG4tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tXG4iOwogCiA/Pg=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
 
error_reporting(-1);
mb_internal_encoding('utf-8');
 
$text = "Кажется, нас обнаружили! Надо срочно уходить отсюда, пока не поздно. Бежим же скорее!";
// Другие варианты для тестов
$text1 = "Ну, прости меня! Не хотела я тебе зла сделать; да в себе не вольна была. Что говорила, что делала, себя не помнила.";
$text2 = "Идет гражданская война. Космические корабли повстанцев, наносящие удар с тайной базы, одержали первую победу, в схватке со зловещей Галактической Империей.";
 
/* Делает первую букву предложения заглавной */

$word = [];  
$phrases = [];
$i = 0;
 
function makeYodaStyleText($text) {
  $phrases = [];
  $i = 0;
  $text = mb_strtolower($text);
  $text = preg_replace("/[,]/","",$text);
  $phrases = preg_split ("/([.|!|?|;])/ui",$text,0,PREG_SPLIT_NO_EMPTY);
  $text = "" ;
  foreach ($phrases as $phrase){
    $phrase = trim($phrase);
    $word = preg_split("/\\s/",$phrase);
    shuffle($word);
    foreach ($word as $idinahooi) {
     $text = $text . $idinahooi . " ";
    }
    $text .= ". ";
    $i++;
  }
  
  return $text;
}

/*делаем первую букву заглавной*/
function makeLetterUp ($match) {
  $first = $match[0];
  $first = mb_strtoupper($first);
  $match[0] = $first;
  return $match[0];
}

/* исправляет текст */
function fixText($text) {
  $letters=[];
  /*делаем первую букву заглавной*/
  $first = mb_substr($text,0,1);
  $first = mb_strtoupper($first);
  $text = mb_substr($text,1);
  $text = $first . $text;
  /*расставляем пробелы*/
  $regexp = "/(\S+)(\s*)([.!?:;]+)(\s*)/ui";
  $text = preg_replace($regexp,"$1$3",$text);
  $regexp = "/([.?!:;]+)([a-zа-яё0-9]+)/ui";
  $text = preg_replace($regexp,"$1 $2",$text);
  /*делаем остальные буквы заглавными*/
  $text = preg_replace_callback ("/[.!?] [\S+]/ui","makeLetterUp",$text);

  return $text;
}
 


$yodaText = makeYodaStyleText($text);
$yodaText = fixText ($yodaText);
echo "Йода говорит: {$yodaText}\n----------------------------------------\n";

$yodaText = makeYodaStyleText($text1);
$yodaText = fixText ($yodaText);
echo "Йода говорит: {$yodaText}\n----------------------------------------\n";

$yodaText = makeYodaStyleText($text2);
$yodaText = fixText ($yodaText);
echo "Йода говорит: {$yodaText}\n----------------------------------------\n";
 
 ?>
PHP 7.0.8 (Legacy: use the following for new features: Command-line PHP: https://repl.it/languages/php_cli PHP Web Server: https://repl.it/languages/php7