Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> problem z własnym bbcode
t3ix
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 16.11.2011

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


Witam (IMG:style_emoticons/default/smile.gif)

Chciałbym żeby mi automatycznie zamieniało tag [player][/player] na link w postaci:

  1. index.php?action=showp&id=ID_UŻYTKOWNIKA


ID_UŻYTKOWNIKA ma zostać wybrane z bazy danych mysql, problem w tym, że nie potrafię wyciągnąć zawartości między [player][/player]

Próbowałem coś z takim kodem:
  1. $txt = preg_replace("#\[player\](.*?)\[/player\]#si","<a href='index.php?action=showp&id=\\1'>\\1</a>",$txt);

Jak \\1 przenieść do zmiennej ?

  1. [player]admin[/player] = <a href="index.php?action=showp&id=1">admin</a>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
t3ix
post
Post #2





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 16.11.2011

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


Problem już rozwiązałem, dzięki za pomoc

  1. $matches = null;
  2. for(;;)
  3. {
  4. preg_match( "#\[player\](.*?)\[/player\]#si" , $tekst , $matches );
  5. if(strlen($matches[1]) < 4) // bo username ma co najmniej 4 znaki
  6. {
  7. break;
  8. }
  9. else
  10. {
  11. $fuser = mysql_real_escape_string($matches[1]);
  12. $row = mysql_fetch_array( mysql_query("...") );
  13. $pid = $row['...'];
  14. $tekst = preg_replace("#\[player\](.*?)\[/player\]#si","<A class='ss' href='index.php?village=$village&action=showp&id=$pid'>\\1</A>",$tekst,1);
  15. }
  16. }
Go to the top of the page
+Quote Post

Posty w temacie


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: 29.12.2025 - 12:21