Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]linki w czacie
Salur
post
Post #1





Grupa: Zarejestrowani
Postów: 179
Pomógł: 0
Dołączył: 28.12.2014

Ostrzeżenie: (20%)
X----


Witam, mam problem ponieważ nie wiem jak połaczyć tresc zmiennej z funkcja wykrywajaca linki. Potrzebuje pomocy aby mi sie robiły automatyczne linki na czacie jak ktos wysle.

  1. zmienna ktora wyswietlam chat:
  2.  
  3. $chat_list .= '<span><strong style="color: #ADD8E6;"><small style="color: black">['.date("H:i:s", $post_item['time']).']</small> '. $post_item['author'].'</strong>: '.$post_item['text'].'</span><br>';
  4.  
  5. funkcja:
  6.  
  7. $texto = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
  8. "<a href=\"\0\">\0</a>", $texto);


Ten post edytował Salur 26.07.2015, 19:51:07
Go to the top of the page
+Quote Post
kapslokk
post
Post #2





Grupa: Zarejestrowani
Postów: 965
Pomógł: 285
Dołączył: 19.06.2015
Skąd: Warszawa

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


  1.  
  2. preg_replace('|([A-Za-z]+://[A-Za-z\.\/#]+)\s|', '<a href="$1">$1</a>', $texto, -1);
  3.  


Nie używa się już ereg.

Ten post edytował kapslokk 27.07.2015, 09:34:00
Go to the top of the page
+Quote Post
Salur
post
Post #3





Grupa: Zarejestrowani
Postów: 179
Pomógł: 0
Dołączył: 28.12.2014

Ostrzeżenie: (20%)
X----


Niestety dalej nie rozumiem, co ma się kryć za zmienną $1, $textto?
Go to the top of the page
+Quote Post
kapslokk
post
Post #4





Grupa: Zarejestrowani
Postów: 965
Pomógł: 285
Dołączył: 19.06.2015
Skąd: Warszawa

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


http://php.net/manual/en/function.preg-replace.php

$1 zostawiasz w spokoju, bo to link znaleziony regexp'em, $texto to tekst, w którym chcesz podlinkować linki smile.gif
Go to the top of the page
+Quote Post
Salur
post
Post #5





Grupa: Zarejestrowani
Postów: 179
Pomógł: 0
Dołączył: 28.12.2014

Ostrzeżenie: (20%)
X----


Zrobiłem tak jak mówisz lecz dalej nie wyświetla automatycznie linków.

  1. $text .= '<span><strong style="color: #ADD8E6;"><small style="color: black">['.date("H:i:s", $post_item['time']).']</small> '. $post_item['author'].'</strong>: '.$post_item['text'].'</span><br>';
  2.  
  3. $chat_list = preg_replace('|([A-Za-z]+://[A-Za-z\.\/#]+)\s|', '<a href="$1">$1</a>', $text, -1);
  4.  
  5. echo $chat_list;
  6.  

Go to the top of the page
+Quote Post
kapslokk
post
Post #6





Grupa: Zarejestrowani
Postów: 965
Pomógł: 285
Dołączył: 19.06.2015
Skąd: Warszawa

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


  1. <?php
  2.  
  3.  
  4. $post_item['text'] = " asdasda spdjaspi djpasjdja http://php.pl asdasdasdasd http://php2.pl asdjais djasod";
  5. $text = '<span><strong style="color: #ADD8E6;"><small style="color: black">['.date("H:i:s", $post_item['time']).']</small> '. $post_item['author'].'</strong>: '.$post_item['text'].'</span><br>';
  6.  
  7. $chat_list = preg_replace('|([A-Za-z]+://[0-9A-Za-z\.\/\?#]+)\s|', '<a href="$1">$1</a> ', $text, -1);
  8.  
  9. echo $chat_list;
  10.  


Coś takiego u mnie działa. Musisz szukać błędu w pozostałej części skryptów.
PS. Dodałem jeszcze 0-9 do regexpa, bo zapomniałem wcześniej.

Ten post edytował kapslokk 27.07.2015, 14:32:48
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 Aktualny czas: 21.08.2025 - 00:04