开发者

php preg_mach a mysql db name

Someone please give me a preg for this

$tbl = '`db_name`.`tbl_name`';

if(preg_match('????',$tbl)){
   echo 'ye';
}else{
   echo 'no'开发者_Python百科;
}

I need the ???? of preg_match, just so:

  • starts with ` (this is the mysql_special comma dont know the name)
  • Followed by a-z,number,underscores
  • followed by ` (mysql)

  • seperated by (dot) .

  • followed by ` (mysql)
  • Followed by a-z,number,underscores
  • followed by ` (mysql)


preg_match('/^`([a-z0-9_]+)`\\.`([a-z0-9_]+)`$/i', $tbl, $matches);


preg_match('/^`(.*?)`\\.`(.*?)`$/i', $tbl, $matches);
$db = $matches[1];
$table = $matches[2];

This is a little more generic. The .*? expression will match all characters until it reaches the character that comes after that expression (in this case, the ` character).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜