Home > php教程 > PHP源码 > body text

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

PHP中文网
Release: 2016-05-25 17:06:41
Original
1939 people have browsed it

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>";
}
?>
Copy after login

                   

                   

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!