Ahojky,
nefunguje mi tento kód:
$slovo = "kočka";
$slovo1 = chunk_split($slovo, 1, ";");
$slovo1 = explode(";", $slovo);
$regular = "";
foreach ($slovo1 as $p) {
switch ($p) {
case "a": $regular .= "([aá]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "b": $regular .= "({1}[\*\-_ \.]*)"; $test .= $p;
break;
case "c": $regular .= "([cč]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "d": $regular .= "([dď]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "e": $regular .= "([eéě]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "f": $regular .= "([f]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "g": $regular .= "([g]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "h": $regular .= "([h]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "i": $regular .= "([ií!]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "j": $regular .= "([j]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "k": $regular .= "([k]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "l": $regular .= "([l]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "m": $regular .= "([m]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "n": $regular .= "([nň]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "o": $regular .= "([oó]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "p": $regular .= "([p]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "q": $regular .= "([q]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "r": $regular .= "([rř]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "s": $regular .= "([sš]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "t": $regular .= "([tť]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "u": $regular .= "([uúů]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "v": $regular .= "([vw]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "w": $regular .= "([vw]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "x": $regular .= "([x]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "y": $regular .= "([yý]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "z": $regular .= "([zž]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "á": $regular .= "([aá]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "č": $regular .= "([cč]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "ď": $regular .= "([dď]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "é": $regular .= "([eéě]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "ě": $regular .= "([eéě]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "í": $regular .= "([ií!]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "ň": $regular .= "([nň]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "ó": $regular .= "([oó]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "ř": $regular .= "([rř]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "š": $regular .= "([sš]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "ť": $regular .= "([tť]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "ú": $regular .= "([uúů]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "ů": $regular .= "([uúů]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "ý": $regular .= "([yý]{1}[\*\-_ \.]*)"; $test .= $p;
break;
case "ž": $regular .= "([zž]{1}[\*\-_ \.]*)"; $test .= $p;
break;
}
$tst .= $p;
}
$zprava = EregI_Replace("$regular", "\\1***\\$k", $zprava);
V proměnné $slovo je teď třeba ta "kočka", toto slovo se rozdělí na jednotlivé znaky a uloží do pole $slovo1 a toto pole se projde pomocí foreach. Ten switch by měl podle písmena uložit určitý text do proměnné $regular, to pak vložit jako regulární výraz do EregI_Replace().
Problém je ten, že mi to píše:
Warning: eregi_replace(): REG_EMPTY in c:\appserv\www\mocaci.cl\mini-chat\chat.php on line 195
tak jsem zkoušel vypsat proměnnou $regular - nevypsalo nic (prázdný řetězec), stejně tak proměnná $test.
Pole je v pořádku - "joint($slovo1);" vypíše "kočka", "$slovo1[1]" vypíše "o". Foreach taky probíhá v pohodě, protože $tst vypíše "kočka".
Takže nechodí jen ten switch, ale já za žádnou cenu nemůžu přijít na to, proč! Nenašel jsem žádnou chybu!
Můžete mi někdo poradit, prosím!
Děkuji!