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 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 (1 - 4)
wewior
post
Post #2





Grupa: Zarejestrowani
Postów: 200
Pomógł: 8
Dołączył: 24.09.2003

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


Jeśli dobrze rozumiem to spróbuj tak:
  1. $txt = '[player]5[/player]';
  2. $link = preg_replace("#\[player\](.*?)\[/player\]#si","<a href='index.php?action=showp&id=\\1'>\\1</a>",$txt);
  3. echo '<pre>';
  4. var_dump( $link );
  5. echo '</pre>';
  6. $matches = null;
  7. preg_match ( "#\[player\](.*?)\[/player\]#si" , $txt , $matches );
  8. echo '<pre>';
  9. var_dump( $matches[1] );
  10. echo '</pre>';


--------------------
- - -
PHP, HTML, JS, Quick.Cms v6.4, Quick.Cart v6.7, Simlery
- - -
Go to the top of the page
+Quote Post
t3ix
post
Post #3





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

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


Tak, po części o to chodziło, dzięki za pomoc smile.gif
Go to the top of the page
+Quote Post
Micchaleq
post
Post #4





Grupa: Zarejestrowani
Postów: 186
Pomógł: 4
Dołączył: 13.10.2009

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


  1. <?php
  2. $nick = "[player]admin[/player]";
  3. $nick = explode("]", $nick);
  4. $nick = explode("[", $nick[1]);
  5. echo '<a href="index.php?action=showp&id=1">'.$nick[0].'</a>';
  6. ?>



Może to cie satysfakcjonuje

Ten post edytował Micchaleq 16.11.2011, 21:59:12


--------------------
Go to the top of the page
+Quote Post
t3ix
post
Post #5





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

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: 22.08.2025 - 10:05