日期:2014-05-17  浏览次数:20595 次

php正则捕获的问题
<connectionStrings>
<add name="AuthContext" providerName="MySql.Data.MySqlClient" connectionString="Data Source=192.168.1.211;port=3307;Initial Catalog=user_info;Persist Security Info=True;User ID=root;Password=ciwcccasdg;MAX Pool Size=2000;Min Pool Size=1;Connection Lifetime=30;Pooling=true;charset=utf8;" />
  <add name="questionconnstr" providerName="MySql.Data.MySqlClient" connectionString="Data Source=192.168.1.65;Initial Catalog=question;User ID=root;Password=root;Pooling=True;charset=utf8;MAX Pool Size=2000;Min Pool Size=1;Connection Lifetime=30;"/>
  </connectionStrings>
要把这里的Data Source=的内容,Initial Catalog=的内容,User ID=的内容,Password=的内容取出来,用正则怎么匹配?

preg_match("/Data Source=(\d+.\d+.\d+.\d+);.*Initial Catalog=(.*?);.*?;User ID=(.*?);Password=(.*?);.*/", $row['connectionString'], $matches);
上面是我的方法,但貌似有问题,新手求指教!

------解决方案--------------------
preg_match_all("/Data Source=([^;]+);.*?Initial Catalog=([^;]+);.*?User ID=(.*?);Password=(.*?);/s", $row['connectionString'], $matches);
print_r($matches);