PHP Forum

PHP Forum (http://www.selfphp.de/forum/index.php)
-   PHP Grundlagen (http://www.selfphp.de/forum/forumdisplay.php?f=12)
-   -   Umstellung auf php7 - Warning: preg_replace(): The /e modifier is no longer supported (http://www.selfphp.de/forum/showthread.php?t=26036)

MikeDD 26.07.2017 10:22:21

Umstellung auf php7 - Warning: preg_replace(): The /e modifier is no longer supported
 
Hallo alle zusammen, ich bin neu hier und hoffe, dass ich das richtige Unterforum getroffen haben. Falls nicht, bitte ich um Nachsicht

Ich stelle meine Webseite gerade von php5 auf php7 um. Leider komme ich an einen Punkt nicht weiter. Ich habe eine Template Klasse. Unter php 5.6 lief diese fehlerfrei, muss jedoch aufgrund php7 umgestellt werden. Leider komme ich an dieser Stelle nicht weiter. Der Original Code ist folgender:

PHP-Code:

protected function replaceFunctions()
** *{

** * * *
// Includes ersetzen ( {include file="..."} )
** * * *while(preg_match("/".$this->leftDelimiterF."include file="(.*).(.*)"".$this->rightDelimiterF."/isUe"$this->template)) {
** * * * * *
$this->template preg_replace("/".$this->leftDelimiterF."include file="(.*).(.*)"".$this->rightDelimiterF."/isUe""file_get_contents(\$this->templateDir.'\\1'.'.'.'\\2')"$this->template);
** * * *}


** * * *
// Kommentare löschen
** * * *$this->template preg_replace("/".$this->leftDelimiterC."(.*)".$this->rightDelimiterC."/isUe"""$this->template);

** * * *return *
true;
** *} *


** *public function 
loop($name$array) {

** * * *
/*
** * * *Sucht nach Einträgen à la {loop=$name}{/loop} und sendet den Inhalt der Klammern an die Funktion loop_content()
** * * *Dabei werden der Name, der "Loop String" und der Datenarray übergeben
** * * **/

** * * *$this->template preg_replace("/".'\{loop="'.$name.'"}'."(.*)".'\{\/loop\}'."/isUe""\$this->loop_content(\$name, '\$1', \$array)"$this->template);
** *}




** *public function 
loop_content($name$string$array) {

** * * *
$output '';

** * * *
$string stripslashes($string); // Kleiner Fix für den String

** * * *foreach($array as $rows) { // Hier geht er den Datenarray durch

** * * * * *$string_tmp $string// Clone von $string, damit $string nicht überschrieben wird

** * * * * *foreach($rows as $row) { // Einzelne Objekte werden durchgegangen
** * * * * * * */*
** * * * * * * *Hier werden Werte à la {$name.key} mit den entsprechenden Werten aus dem Array ersetzt
** * * * * * * **/
** * * * * * * *$string_tmp str_replace($this->leftDelimiter.$name.".".key($rows).$this->rightDelimiter$row$string_tmp);
** * * * * * * *
next($rows); * *
** * * * * *}

** * * * * *
$output .= $string_tmp;
** * * *}

** * * *return 
$output;

** *} * 

Bei diesem Code bekomme ich folgende Fehler...

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/htdocs/w0xxxxx/abc/test.de/class/template.php on line 207

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/htdocs/w0xxxxx/abc/test.de/class/template.php on line 212

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/htdocs/w0xxxxx/abc/test.de/class/template.php on line 225



Folgendes habe ich bereits umgesetzt. Jedoch bin ich mir nicht sicher, ob dies so der richtige Weg ist...

PHP-Code:

protected function replaceFunctions()
** *{

** * * *
// Includes ersetzen ( {include file="..."} )

** * * *$this->template preg_replace_callback("/{include file="(.*).(.*)"}/",
** * * * * * * * * *function (
$treffer) {



** * * * * * * * * * * *
$aufruf $this->templateDir.''.$treffer[1].'.'.$treffer[2];


** * * * * * * * * * * *return 
file_get_contents($aufruf);
** * * * * * * * * *}, 
$this->template);


** * * *
// Kommentare löschen
** * * *#$this->template = preg_replace("/".$this->leftDelimiterC."(.*)".$this->rightDelimiterC."/isUe", "", $this->template);

** * * *return *true;


** *} 


Wäre über Tipps und Hilfestellung dankbar.

Viele Grüße
Mike

chorn 26.07.2017 10:39:06

AW: Umstellung auf php7 - Warning: preg_replace(): The /e modifier is no longer suppo
 
macht es denn was du willst? Hast du Testfälle definiert?

MikeDD 26.07.2017 10:45:35

AW: Umstellung auf php7 - Warning: preg_replace(): The /e modifier is no longer suppo
 
Das zweite Codebeispiel macht, meiner Ansicht nach was es soll. Ich denke mal das die function loop() auch mit einer callback function ausgestattet werden muss. Jedoch finde ich da keinen Ansatz.

MikeDD 26.07.2017 11:34:14

AW: Umstellung auf php7 - Warning: preg_replace(): The /e modifier is no longer suppo
 
die Funktion

PHP-Code:

protected function replaceFunctions() 
** *{ 

** * * *
// Includes ersetzen ( {include file="..."} ) 

** * * *$this->template preg_replace_callback("/{include file="(.*).(.*)"}/"
** * * * * * * * * *function (
$treffer) { 



** * * * * * * * * * * *
$aufruf $this->templateDir.''.$treffer[1].'.'.$treffer[2]; 


** * * * * * * * * * * *return 
file_get_contents($aufruf); 
** * * * * * * * * *}, 
$this->template); 


** * * *
// Kommentare löschen 
** * * *#$this->template = preg_replace("/".$this->leftDelimiterC."(.*)".$this->rightDelimiterC."/isUe", "", $this->template); 

** * * *return *true


** *} 

macht was sie soll. Ob diese von der Syntax richtig ist bin ich mir jetzt nicht 100% sicher. Die Function loop läuft jedoch nicht und alle Versuche diese mit einen callback auszustatten schlagen fehl.

vt1816 26.07.2017 15:49:38

AW: Umstellung auf php7 - Warning: preg_replace(): The /e modifier is no longer suppo
 
Sei doch bitte so nett und ändere die Einstellungen Deines bevorzugten Editors (vermute mal Notepad++).
Denn vor lauter Sternen (".. Leerzeichen keine Leerzeichen waren (Hex: 0x20) sondern (Hex: 0xa0)") sieht man ja kaum den Code - Danke!

MikeDD 26.07.2017 15:53:21

AW: Umstellung auf php7 - Warning: preg_replace(): The /e modifier is no longer suppo
 
Sorry.

Die Function, welche funktioniert sieht so aus...

PHP-Code:


protected function replaceFunctions()
    {
        
        
// Neu für php 7
        
$this->template preg_replace_callback("/{include file=\"(.*)\.(.*)\"}/"
                    function (
$treffer) {
                        
$aufruf $this->templateDir.''.$treffer[1].'.'.$treffer[2];
                        return 
file_get_contents($aufruf);
                    }, 
$this->template);
                    
        
// Kommentare löschen
        
$this->template preg_replace_callback("/<!--(.*)-->/"
                    function (
$treffer) {                        
                        return 
str_replace($treffer[0], ""$treffer[0]);
                    }, 
$this->template);
        
        return  
true;
    } 

Aktuell hänge ich an dieser Funktion.

PHP-Code:


public function loop($name$array) {
        
        
msg('loop function: '.$name);
        
        
/*
        Sucht nach Einträgen à la {loop=$name}{/loop} und sendet den Inhalt der Klammern an die Funktion loop_content()
        Dabei werden der Name, der "Loop String" und der Datenarray übergeben
        */

        
$this->template preg_replace("/".'\{loop="'.$name.'"}'."(.*)".'\{\/loop\}'."/isUe""\$this->loop_content(\$name, '\$1', \$array)"$this->template);


}


public function 
loop_content($name$string$array) {
        
        
$output '';
        
        
$string stripslashes($string); // Kleiner Fix für den String
        
        
foreach($array as $rows) { // Hier geht er den Datenarray durch
            
            
$string_tmp $string// Clone von $string, damit $string nicht überschrieben wird
            
            
foreach($rows as $row) { // Einzelne Objekte werden durchgegangen
                /*
                Hier werden Werte à la {$name.key} mit den entsprechenden Werten aus dem Array ersetzt
                */
                
$string_tmp str_replace($this->leftDelimiter.$name.".".key($rows).$this->rightDelimiter$row$string_tmp);
                
next($rows);    
            }
            
            
$output .= $string_tmp;
        }
        
        return 
$output;
        



Diese bringt weiterhin die Fehlermeldungen...

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/htdocs/w0xxxxx/abc/test.de/class/template.php on line 207

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/htdocs/w0xxxxx/abc/test.de/class/template.php on line 212

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/htdocs/w0xxxxx/abc/test.de/class/template.php on line 225


Alle Zeitangaben in WEZ +2. Es ist jetzt 14:11:13 Uhr.

Powered by vBulletin® Version 3.8.3 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.