我需要一些帮助,使我的2-3代码折磨的PHP代码。 Ny方法尝试但没有结果。我想借此@后的第一个和第二个字,例如@约翰母鹿和PHP的结果却让我约翰和李四PHP获得第一个和第二个词后(在)
我一点东西: (编辑)
$q = 'Hi @Stefan Simeonov kak si? @Krasi avramov';
if (preg_match_all("(@[^ ]+[ ][^ ]+)", $q, $match)) {
foreach ($match[0] as $singleMatch) {
$finded[] = $singleMatch;
$success = 1;
}
} elseif (preg_match_all("(@[^ ]+)", $q, $match)) {
foreach ($match[0] as $singleMatch) {
$finded[] = $singleMatch;
$success = 1;
}
} else {
$success = 0;
}
if($success = 1) {
$replace = $q;
foreach ($finded as $user) {
$expl = explode("@",$user);
$rep = '<a href="?profile='.$expl[1].'">'.$expl[1].'</a>';
$replace = str_replace($user,$rep,$replace);
}
echo $replace;
} else {
echo $q;
}
您需要添加一些代码,指出您可能出错的地方以及您期望的结果。 – mavrosxristoforos
http://regular-expressions.info/tutorial.html – deceze
在一个字符串中可以有多个@ ...吗? –