正则从汉字字符串中取某一个汉字
<?php<br>header("Content-type: text/html; charset=gb2312"); <br>$regex = '/大(\xhh{1})好啊/'; //这里该如何去写,我不会正则,希望大家能帮我解答一下,谢谢<br>$str = '大家好啊';<br>$matches = array();<br> <br>if(preg_match($regex, $str, $matches)){<br> var_dump($matches);<br>}<br>?>我想取出“家”字
------解决方案--------------------
header("Content-type: text/html; charset=gb2312"); <br>$regex = '/大(.*?)好啊/';<br>$str = '大家好啊';<br>$str= mb_convert_encoding($str,'gb2312','UTF-8');<br>$regex = mb_convert_encoding($regex,'gb2312','UTF-8');;<br>$matches = array();<br> <br>if(preg_match($regex, $str, $matches)){<br> var_dump($matches);<br>//array(2) { [0]=> string(12) "大家好啊" [1]=> string(3) "家" }<br>}










