我想问下我的正则是哪里错了? 你的结果是array(3) { [0]=> string(9) "[hehe] string(6) "[hehe]" [2]=> string(3) " <m" } 不知道你想要的结果是什么样的??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">期待取出这段 "/<meta.*?>/"用这个试试 preg_match("/\[hehe\]([^\[hehe\]].*)\[\/hehe\]/i",'[hehe] <meta http-equiv="Content-Type" content="text/html; charset=gb2312">[/hehe]', $test); var_dump($test); "/<meta[^\>]*>/i"试试 preg_match("/\[hehe\]+([^>]+)/ie",'[hehe]<meta http-equiv="Content-Type" content="text/html; charset=gb2312">[/hehe]', $test); print_r($test); <?phppreg_match("/\[hehe\](.*)\[\/hehe\]/i",'[hehe] <meta http-equiv="Content-Type" content="text/html; charset=gb2312">[/hehe]', $test);var_dump($test);?> preg_match("/(\[hehe\])(.*)(\[\/hehe\])/i",'[hehe] <meta http-equiv="Content-Type" content="text/html; charset=gb2312">[/hehe]', $test); var_dump($test); [hehe]<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312">[/hehe]我的意思是里面不一定只有一条的 <?php preg_match("/(\[hehe\])(.*)(\[\/hehe\])/i",'[hehe] <meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312">[/hehe]', $test); var_dump($test); ?> 结果是: [2]不是你要的吗?array(4) { [0]=> string(287) "[hehe] <meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312">[/hehe]" [1]=> string(6) "[hehe]" [2]=> string(274) " <meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312">" [3]=> string(7) "[/hehe]"} array(4) { [0]=> string(291) "[hehe] [/hehe]" [1]=> string(6) "[hehe]" [2]=> string(278) " " [3]=> string(7) "[/hehe]" } - -为什么我是这样的。迷茫一下下 preg_match("/(\[hehe\])(.*)(\[\/hehe\])/i",'[hehe] <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta http-equiv="Content-Type" content="text/html; charset=gb2312">[/hehe]', $test); var_dump($test); array(4) { [0]=> string(291) "[hehe] [/hehe]" [1]=> string(6) "[hehe]" [2]=> string(278) " " [3]=> string(7) "[/hehe]" } <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />如果我要取出 gb2312或UTF-8要怎么样写呢? 网站与dz论坛用ucenter整合第一次登陆同步问题. php生成可订阅的rss的问题 PHP获得前台Post上来的变量的问题 請高手幫忙看一下我或是哪邊出問題! 一個有關WAV的處理! ffmpeg 运行的问题 变量的处理,请帮忙 简单的正则,大家帮帮忙 MySQL在PHP5环境下的配置问题 谁有用PHP写的"阿江酷站访问统计系统" 谁能帮我写段代码呵?大家中秋快乐,高分呵,庆祝, CSDN分换一个discuz官方论坛的旧帐号~~~ mysql数据库与php编码问题,IE中输出是乱码.
期待取出这段
用这个试试
var_dump($test);
试试
print_r($test);
preg_match("/\[hehe\](.*)\[\/hehe\]/i",'[hehe] <meta http-equiv="Content-Type" content="text/html; charset=gb2312">[/hehe]', $test);
var_dump($test);
?>
var_dump($test);
preg_match("/(\[hehe\])(.*)(\[\/hehe\])/i",'[hehe] <meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312">[/hehe]', $test);
var_dump($test);
?>
结果是: [2]不是你要的吗?
array(4) {
[0]=>
string(287) "[hehe] <meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312">[/hehe]"
[1]=>
string(6) "[hehe]"
[2]=>
string(274) " <meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta http-equiv="Content-Type" content="text/html; charset=gb2312">"
[3]=>
string(7) "[/hehe]"
}
var_dump($test);
array(4) { [0]=> string(291) "[hehe] [/hehe]" [1]=> string(6) "[hehe]" [2]=> string(278) " " [3]=> string(7) "[/hehe]" }
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
如果我要取出 gb2312或UTF-8要怎么样写呢?