Home  >  Article  >  php教程  >  PHP运用正则表达式获取字符串中的特定字符

PHP运用正则表达式获取字符串中的特定字符

PHP中文网
PHP中文网Original
2016-05-25 17:06:411945browse

1. [PHP]代码  

<?php
$db = new PDO("mysql:host=localhost;dbname=album", &#39;root&#39;, &#39;&#39;);
$db->query("set names gb2312");
$sql="SELECT * FROM `sales`";
$rows = $db->query($sql)->fetchall();
foreach($rows as $row)
{
$str  =  $row[&#39;detail&#39;];  
preg_match("/[".chr(0xa1)."-".chr(0xff)."]{4}市/",$str,$regs);  
echo $regs[0]?$regs[0]:&#39;暂无&#39;;
echo "<br>";
}
?>

                   

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn