Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: modyfikacja kodu PHP
Forum PHP.pl > Forum > PHP
alkesz1718
Witam, mam moduł chata lecz po zaktualizowaniu silnika strony wyskakuje mi błąd:
Cytat
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/u580717928/public_html/engine/modules/iChat/ajax/add.php on line 237


ten błąd dotyczy tych 3 kodów:
  1. $message = preg_replace("#\[leech\](\S.+?)\[/leech\]#ie", "\iChat_build_url(array('html' => '\\1', 'show' => '\\1'))", $message);
  2. $message = preg_replace("#\[leech\s*=\s*\&quot\;\s*(\S+?)\s*\&quot\;\s*\](.*?)\[\/leech\]#ie", "\iChat_build_url(array('html' => '\\1', 'show' => '\\2'))", $message);
  3. $message = preg_replace("#\[leech\s*=\s*(\S.+?)\s*\](.*?)\[\/leech\]#ie", "\iChat_build_url(array('html' => '\\1', 'show' => '\\2'))", $message);


gdy zmienię je na:
  1. $message = preg_replace_callback("#\[leech\](\S.+?)\[/leech\]#ie", "\iChat_build_url(array('html' => '\\1', 'show' => '\\1'))", $message);
  2. $message = preg_replace_callback("#\[leech\s*=\s*\&quot\;\s*(\S+?)\s*\&quot\;\s*\](.*?)\[\/leech\]#ie", "\iChat_build_url(array('html' => '\\1', 'show' => '\\2'))", $message);
  3. $message = preg_replace_callback("#\[leech\s*=\s*(\S.+?)\s*\](.*?)\[\/leech\]#ie", "\iChat_build_url(array('html' => '\\1', 'show' => '\\2'))", $message);

wyskakuje mi błąd:
Cytat
Warning: preg_replace_callback(): Requires argument 2, '\iChat_build_url(array('html' => '\1', 'show' => '\2'))', to be a valid callback in /home/u580717928/public_html/engine/modules/iChat/ajax/add.php on line 238


Gdy usunę te 3 linijki błędy nie wyskakują ale tag do linku [leech*] nie działa i wyświetla jako tekst zamiast odnośnika...

Teraz pytanie jak poprawnie zmodyfikować ten kod by działał?

Poniżej podam przykład kodu jaki jest stosowany w silniku:
  1. $source = preg_replace_callback( "#\[(leech)\](\S.+?)\[/leech\]#i", array( &$this, 'build_url'), $source );
  2. $source = preg_replace_callback( "#\[(leech)\s*=\s*\&quot\;\s*(\S+?)\s*\&quot\;\s*\](.*?)\[\/leech\]#i", array( &$this, 'build_url'), $source );
  3. $source = preg_replace_callback( "#\[(leech)\s*=\s*(\S.+?)\s*\](.*?)\[\/leech\]#i", array( &$this, 'build_url'), $source );


Tomplus
Skorzystaj z manuala:
http://php.net/manual/en/function.preg-replace-callback.php

Tam w przykładach masz pokazane jak stosować callback.

Ogólenie metoda prosta:
  1. preg_replace_callback($wyrazenieRegularne, "nazwaFunkcji", $tresc);
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.