Categories
Programming/php

[php] regular expression match

preg_match( '/c=([0-9]+)/' , $t->log['dest_query'] , $data);
這樣可以取出 c=xxxx

抓 user agent 版本

preg_match( '/MSIE ([0-9]+.[0-9])/' , $_SERVER['HTTP_USER_AGENT'] , $data_msie_ver);
preg_match( '/Windows NT ([0-9]+.[0-9])/' , $_SERVER['HTTP_USER_AGENT'] , $data_nt_ver);
  if ( !( (float)$data_msie_ver[1]>=6 && (float)$data_msie_ver[1]<=8 ) ) $valid_useragent = 0;