PHP preg匹配无法正常工作

时间:2012-02-10 20:01:31

标签: php notifications match

我的php的preg_match有问题。我想做这样的事情: 当有人在论坛上发布某人的用户名(例如:@Username text ..)来执行mysql查询以向数据库插入通知。

我已经制作了这段代码:

<?php 
$this = mysql_query("SELECT id,username FROM users");
while($the = mysql_fetch_array($this)){
if(preg_match("/^@".$the['username']."/",$form_text)){
 mysql_query("INSERT INTO notifications (num,who) VALUES ('$forum_id','".$the['username']."')");
}    
?>

但有些东西不起作用。我该如何解决? 感谢。

1 个答案:

答案 0 :(得分:0)

尝试并使用:

if (strpos( $form_text , $the['username'] ) !== false)

希望这有帮助。

编辑:您还应该保护自己免受SQL注入,查找此页面: http://php.net/manual/en/security.database.sql-injection.php

相关问题