Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] BBCode - parsowanie linków z [url(=)][/url] i bez tego, Czyli wychodzą linki w linkach ;/
infoo1
post
Post #1





Grupa: Zarejestrowani
Postów: 117
Pomógł: 0
Dołączył: 12.11.2008

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


  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]
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
RafaelX
post
Post #2





Grupa: Zarejestrowani
Postów: 144
Pomógł: 28
Dołączył: 2.01.2009

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


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

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

 



RSS Aktualny czas: 22.08.2025 - 15:43