PHP运用正则表达式获取字符串中的特定字符
程序员文章站
2022-05-05 22:05:37
...
1. [PHP]代码
<?php $db = new PDO("mysql:host=localhost;dbname=album", 'root', ''); $db->query("set names gb2312"); $sql="SELECT * FROM `sales`"; $rows = $db->query($sql)->fetchall(); foreach($rows as $row) { $str = $row['detail']; preg_match("/[".chr(0xa1)."-".chr(0xff)."]{4}市/",$str,$regs); echo $regs[0]?$regs[0]:'暂无'; echo "<br>"; } ?>