Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] BBCode - parsowanie linków z [url(=)][/url] i bez tego
Forum PHP.pl > Forum > Przedszkole
infoo1
  1. <?php
  2. private function urls()
  3.        {
  4.            #$this->code = preg_replace('/(.*?)/','<a href="${1}">${1}</a>',$this->code);
  5.            #$this->code = preg_replace('/(.*?)/','<a href="${1}">${2}</a>',$this->code);
  6.  
  7.  
  8.            $this->code = preg_replace('/http://(.*?)/','<a href="http://${1}">http://${1}</a>',$this->code);
  9.            $this->code = preg_replace('/www.(.*?)/','<a href="http://www.${1}">www.${1}</a>',$this->code);
  10.  
  11.            $this->code    =    preg_replace("#(.*?)#si", "<a href=\"1\">1</a>",$this->code);
  12.            $this->code    =    preg_replace("#(.*?)#si", "<a href=\"1\">2</a>",$this->code);
  13.            return true;
  14.        }
  15. ?>
Co zrobić, aby parsowało , , http://cos, www.cos, i http://www.cos, ale nie może się "nadpisywać", tak jak w tej chwili, czyli najpierw parsuje funkcja wyłapująca linki bez [url(=)][/url], a potem jeszcze ta z [url(=)][/url] i wychodzi np. takie coś:
Kod
<a href="<a href="http://">http://</a>google.pl/"><a href="http://">http://</a>google.pl/</a>
z tego
Kod
[url]http://google.pl/[/url]
RafaelX
  1. <?php
  2. private function urls()
  3.       {
  4.          
  5.           $this->code = preg_replace('/http://(.*?)/','<a href="http://${1}">http://${1}</a>',$this->code);
  6.           $this->code = preg_replace('/www.(.*?)/','<a href="http://www.${1}">www.${1}</a>',$this->code);
  7.  
  8.           $this->code = preg_replace("#(.*?)#si", "<a href=\"1\">2</a>",$this->code);
  9.           $this->code = preg_replace("#(.*?)#si", "<a href=\"1\">1</a>",$this->code);
  10.          
  11.  
  12.  
  13.  
  14.  
  15.           return true;
  16.       }
  17. ?>
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.