Benvenuto Posted August 14, 2003 Report Posted August 14, 2003 <code><font color="#000000"> ereg_replace (" is", " was", $string); </font> </code> shinii rindinjaa is repleisos ar was, bet man ir jautaajums kaa vareetu uzreiz defineet visus burtus vai vaardus kurus veelos repleisot un visus tos burtus vai vaardus kurus gribu likt to vietaa taa, lai nebuutu katru reizi jaaraksta ereg_replace... rindinja?
Little_Hacker Posted August 14, 2003 Report Posted August 14, 2003 /me nezini bet taa uz aatru domu iedomaajos ka mozh ar masiiviem (array) ?! Kaut ko vareetu sabiidiit.. man skjiet ka php manuaali ir kaut kaads liidziigs paraugs.. :blink:
bassz Posted August 15, 2003 Report Posted August 15, 2003 <?php function censor($text) { $mask = "-"; $badwords = array("badword1", "badword2", "badword3"); for ($i = 0; $i < sizeof($words); $i++) { $censored = substr($badwords[$i], 0, 1); for ($x = 1; $x < strlen($badwords[$i]); $x++) $censored .= $mask; $text = str_replace($badwords[$i], $censored, $text); } return $text; } ?>
Kaklz Posted August 16, 2003 Report Posted August 16, 2003 <code><font color="#000000"> ereg_replace (" is", " was", $string);</font> </code> shinii rindinjaa is repleisos ar was, bet man ir jautaajums kaa vareetu uzreiz defineet visus burtus vai vaardus kurus veelos repleisot un visus tos burtus vai vaardus kurus gribu likt to vietaa taa, lai nebuutu katru reizi jaaraksta ereg_replace... rindinja? mosh nevis ereg_replace, bet preg_replace? ;) Quote from: http://lv.php.net/manual/en/function.preg-replace.php If pattern and replacement are arrays, then preg_replace() takes a value from each array and uses them to do search and replace on subject.
Venom Posted August 17, 2003 Report Posted August 17, 2003 Bet, ja neizmanto ereg_ un preg_ nevietā, tad noder šāda fiška: $translate=array( ' is '=>'was', ' does '=>' did ' ); $text=strtr($text,$translate) echo $text; Atkal, ja piem. jānomaina case-insensitive (jebšu is, IS, Is vai iS vienalga jānomaina par was), izmanto to pašu fišku, bet tad vienā arrajā liek patternus (šājā gadījumā varētu izskatīties kā (ja forums atkal nenoēdīs slashus) '/\b(vārds)\b/imU') bet citā - "tulkojumus". See preg_replace() man.
Benvenuto Posted August 17, 2003 Author Report Posted August 17, 2003 jaa preg replace vareetu nodereet. :)
Recommended Posts