22/06/12 19:41
riddick
Salve a tutti, in pratica ho questo problema, riesco a parsare i testi e a individuare quello che mi serve ovvero il nome preceduto da #, tipo #nomecognome, solo che alcune volte mi prende e converte questi tag in link e altre volte no. Il fatto strano è che, siccome ho un sistema di notifiche quando si tagga una persona, la notifica ti tag arriva, solo che non mi sostituisce il #nomecognome con il relativo link al profilo. Qui il codice e per qualsiasi cosa se non mi sono spiegato ve la dico:
public function GetTag ($text) { $matches = array(); $replacements = array(); preg_match_all('/#([^s]+)/', $text, $matches); $this->DBConnect(); $sql = mysql_query("SELECT * FROM users"); while ($rows = mysql_fetch_array($sql)) { for ($j = 0, $c = count($matches[1]); $j < $c; $j++) { $str = strtolower(str_replace(' ', '', $this->GetNameSurname($rows['id']))); if ($str == $matches[1][$j]) { $replacements[$j] = "<a href='profile.php?user=".$rows['id']."'>".$this->GetNameSurname($rows['id'])."</a>"; } else { $replacements[$j] = $matches[1][$j]; } } } for ($j = 0, $c = count($matches[1]); $j < $c; $j++) $text = str_replace($matches[1][$j], $replacements[$j], $text); return $text; }
aaa