Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> modyfikacja kodu PHP
alkesz1718
post 2.01.2017, 18:16:08
Post #1





Grupa: Zarejestrowani
Postów: 98
Pomógł: 0
Dołączył: 8.12.2014
Skąd: Czernina

Ostrzeżenie: (0%)
-----


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


Go to the top of the page
+Quote Post
Tomplus
post 2.01.2017, 19:11:10
Post #2





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 230
Dołączył: 20.03.2005
Skąd: Będzin

Ostrzeżenie: (0%)
-----


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);
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 21.06.2025 - 23:09