ereg replace

marco_rx

Utente Attivo
19 Dic 2010
129
0
0
Mi sembra di aver letto che la funzione ereg_replace è caduta in disuso e quindi è stata tolta nelle nuove versioni di PHP
c'è un'altra funzione che svolge lo stesso compito, cioè sostituisce in una textarea tutti i caratteri che segnalano una nuova riga con il tag br?
 

Trogo

Utente Attivo
11 Gen 2008
370
0
0
43
Sanremo
Hai ragione, la funzione (come tutte le regex POSIX) è stata deprecata dalla versione 5.3.0 di PHP (che è un po' diverso da essere caduta in disuso). Prova a vedere a questa pagina, dove vengono confrontate le funzioni POSIX e PCRE.
 

marco_rx

Utente Attivo
19 Dic 2010
129
0
0
Si non avevo capito cos'era successo, comunque ho trovato la funzione nl2br() che mi sembra sia simile, almeno per quello a cui serviva a me
 

seaport

Nuovo Utente
3 Apr 2015
2
0
0
Buongiorno, son nuovo del forum. Ho il seguente problema, non sono esperto di programmazione, ma prendendo spunto qua e là riesco a far funzionare il mio sito. Da qualche giorno non mi funziona più il file template che uso insieme a php. Il passaggio da posix a pcre(qiundi mi riferisco al cambiamento dei codici ereg ecc...) non riesco a gestirlo da solo, ho provato, ma nulla, quindi cortesemente se possibile avrei bisogno di un aiuto nel convertire le poche stringhe del file.
allego il codice che ho necessità di trasformare, se qualcuno può darmi una mano sarei molto grato. grazie.
<?

class Template {
var $template_file,
$buffer,
$foreach,
$content,
$debug;

function Template($filename,$debug = "") {
$this->template_file = $filename;
$this->debug = $debug;
$fp = fopen ($filename, "r");
$this->buffer = fread($fp, filesize($filename));
fclose($fp);
$i=0;
do {
$result = ereg("<\[foreach\]>(.+)<\[\/foreach\]>",$this->buffer,$token);
if ($result) {
$this->foreach[] = $token[1];
$this->buffer = ereg_replace("<\[foreach\]>.+<\[\/foreach\]>","<[foreach$i]>",$this->buffer);
}
} while ($result);
}

function setContent($name, $value) {
$this->content[$name][] = $value;
}

function setContent2($name, $value = "") {

if (gettype($name) == "array") {
foreach($name as $k => $v) {
$this->content[$k][] = $v;
}
} else {
$this->content[$name][] = $value;
}
}

function pre($var) {
if ($this->debug == "DEBUG") {
return "<!- begin:$var -->";
}
}

function post($var) {
if ($this->debug == "DEBUG") {
return "<!- end:$var -->";
}
}

function parse() {

if ($this->debug == "DEBUG") {
$pre = "<!- \$token[1] -->";
$post = "<!- \$token[1] -->";
}

for($i=0;$i<count($this->foreach);$i++) {

$result = ereg("<\[([[:alnum:]]+)\]>",$this->foreach[$i],$token);
if ($result) {
$iterations = count($this->content[$token[1]]);
}
for ($j=0;$j<$iterations;$j++) {
$buffer = $this->foreach[$i];
do {
$result = ereg("<\[([[:alnum:]]+)\]>",$buffer,$token);
if ($result) {
$buffer = ereg_replace("<\[$token[1]\]>",$this->pre($token[1]).$this->content[$token[1]][$j].$this->post($token[1]),$buffer);
}
} while ($result);
$this->content["foreach$i"][0] .= $buffer;
}
}

do {
$result = ereg("<\[([[:alnum:]]+)\]>",$this->buffer,$token);
if ($result) {
$this->buffer = ereg_replace("<\[$token[1]\]>",$this->pre($token[1]).$this->content[$token[1]][0].$this->post($token[1]),$this->buffer);
}
} while ($result);
}

function close() {
echo $this->buffer;
}

function get() {
return $this->buffer;
}

}

?>
 

Discussioni simili