我需要一些 php 代码的帮助,这折磨了我 2-3 个小时。Ny 方法尝试但没有结果。我想在 @ 之后取第一个和第二个词,例如@John Doe和 php 结果带我 John 和 Doe
我的事情是:(已编辑)
$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;
}