开发者

php preg_mach a mysql db name

开发者 https://www.devze.com 2023-02-14 17:08 出处:网络
Someone please give me a preg for this $tbl = \'`db_name`.`tbl_name`\'; if(preg_match(\'????\',$tbl)){

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

精彩评论

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