基本上,当一个表单在评论和评论中提交时,它包含@username
或@
个人的用户名,我想做点什么,例如:向用户名发送通知。
所以,如果它之后包含@
和一个单词(带字母或数字),我想得到它并用它做点什么。
e.g。
if (contains an @ symbol, get the value of it) {
// do something
}
答案 0 :(得分:1)
$str = 'hello @user';
preg_match('/@([a-z0-9]+)/i', $str, $matches);
// $matches[0] = '@user';
// $matches[1] = 'user';
答案 1 :(得分:0)
使用此代码,您将能够检查字符串是否包含“@”。
if(strpos('My @string', '@') !== false)
{
//Actions if it found a @ in the string
}
else
{
//Actions if it didn't found a @ in the string
}
答案 2 :(得分:0)
如果您使用\w
代替[a-z0-9]
,则会抓住有效_
的{{1}}个字符。
user_names