Jump to content
php.lv forumi

Ereg_replace


Benvenuto

Recommended Posts

<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?

Link to comment
Share on other sites

<?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;

}

?>

Link to comment
Share on other sites

<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.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

×
×
  • Create New...