Autor Zpráva
malek
Profil
ako dostanem
z
$text="bla bla [hracid=33] bla bla";

toto :

bla bla http://str.php?id=33 bla bla ?

$text = ereg_replace("\[hracid=[0123456789]+\]","<a href='stranka.php?id=""'>hrac</a>", $text);

len neviem ako id tam dostanem

rozmyslal som ze cez str_repleace premenim [hracid= na <a href='stranka.php?id="
a ] na "'>hrac</a> ale ak bude v texte len ] tak to narobi galibu :)
Retal
Profil
$text = preg_replace('|\[hracid=(\d+)\]|', '<a href="/str.php?id=\1">Hráč \1</a>', $text);
malek
Profil
dakujem, a keby som chcel to id dat do premeny $id?
hlavne ak by som chcel vyhladat to id v databaze miesto hrac dat meno hraca?

<a href='stranka.php?id=33>peter</a>

$text = preg_replace('|\[hracid=(\d+)\]|', $id=\1, $text); zeby? :D idem skusit
Retal
Profil
Ne, to ti nepůjde. Já bych použil modifikátor "e" a prohnal výsledek regexpu PHP funkcí. Asi takto:


function vratJmenoHrace($id) {
... // kod pro urceni jmena hrace
return $jmeno;
}

$text = preg_replace('|\[hracid=(\d+)\]|e', '"<a href=\"/str.php?id=\\1\">".vratJmenoHrace(\\1)."</a>"', $text);
Toto téma je uzamčeno. Odpověď nelze zaslat.

0