• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php正则匹配问题

php 搞代码 3年前 (2022-01-23) 26次浏览 已收录 0个评论
文章目录[隐藏]

$t=’

chrome

test

‘;
$pre_reg = ‘/

.*? preg_match_all($pre_reg,$t,$matches);
print_r($matches);

$t我省略了其他的,只留下了主要信息,但即便如此还是无法输出,请问这是什么问题
(我的原意是匹配

chrome 中的D8%C1%D0%CB%B9和chrome)

回复讨论(解决方案)

$pre_reg = ‘/

.*?

$t='<tr><td>chrome</td><tr><td>test</td>';$find='/href="\/f\?kw=([^"]*?)"\stitle="([^"]*?)"/s';preg_match_all($find,$t,$res);echo "<pre class="prettyprint linenums">";print_r($res);echo "

“;/*Array( [0] => Array ( [0] => href=”/f?kw=chrome” title=”chrome” [1] => href=”/f?kw=%CA%A5%B0%B2%B5%” title=”test” ) [1] => Array ( [0] => chrome [1] => %CA%A5%B0%B2%B5% ) [2] => Array ( [0] => chrome [1] => test ))*/

$t='<tr><td>chrome</td><tr><td>test</td>';$find='/href="\/f\?kw=([^"]*?)"\stitle="([^"]*?)"/s';preg_match_all($find,$t,$res);echo "<pre class="prettyprint linenums">";print_r($res);echo "

“;/*Array( [0] => Array ( [0] => href=”/f?kw=chrome” title=”chrome” [1] => href=”/f?kw=%CA%A5%B0%B2%B5%” title=”test” ) [1] => Array ( [0] => chrome [1] => %CA%A5%B0%B2%B5% ) [2] => Array ( [0] => chrome [1] => test ))*/

似乎还是不对,这是我原本的数据:

<meta charset=”gbk”>管理我喜欢的吧_百度贴吧 <link rel=”shortcut icon” href=”http://static.tieba.baidu.com/tb/favicon.ico&#8221; /><link id=”css_head_0″ href=”http://static.tieba.baidu.com/tb/static-member/style/forums.css?v=1222222&#8243; type=”text/css” rel=”stylesheet”/>
<script id=”js_head_0″ src=”http://static.tieba.baidu.com/tb/static-member/js/forums.js?v=1222222&#8243; type=”text/javascript”></script>
<script type=”text/javascript”>var TbConf = {‘domain’ : {“TB_STATIC”:”http://static.tieba.baidu.com/&#8221;,”TB”:”http://tieba.baidu.com/&#8221;,”PASSPORT”:”http://passport.baidu.com/&#8221;,”MSG”:”http://msg.baidu.com/&#8221;,”SPACE”:”http://hi.baidu.com/&#8221;,”UFACE”:”http://tb.himg.baidu.com/&#8221;,”IMGSRC”:”http://imgsrc.baidu.com/&#8221;,”ZYQ_AD”:”http://a.baidu.com/&#8221;,”ZYQ_SMALL_PIC”:”http://imgsrc.baidu.com/forum/abpic/item/&#8221;,”TB_UPLOAD”:”http://upload.tieba.baidu.com/&#8221;}};var Tbs = “b62b84c39c54e4971407421926”;</script><body><style>.forum_main{padding-left: 2px;}.forum_note{background-color: #FEFFDB;border: 1px solid #FFD99C;color: #6C6C6E;padding: 4px 15px;width:480px;}.forum_title{margin-top: 30px;}.forum_table{margin-top: 15px;}.forum_table table{width:100%;border-collapse:collapse; border: solid #DADFE8;border-width:0 1px 1px 0;}.forum_table table th, .forum_table table td { border-collapse:collapse; border: solid #DADFE8; border-width:1px 0 0 1px; vertical-align:middle; text-align:center; }.forum_table table th{font-size: 14px;font-weight: bold;height: 36px;}.forum_table table td{height: 36px;}.forum_tips{margin-top:20px;}.addfav{background-image: url(“http://static.tieba.baidu.com/tb/static-member/img/blueplus.png&#8221;);display: block;height: 25px;width: 73px;margin: 0 auto;cursor:pointer;}.canfav{background-image: url(“http://static.tieba.baidu.com/tb/static-member/img/cancel_like.png&#8221;);display: block;height: 25px;width: 98px;margin: 0 auto;}.canfav_text{color: blue;left: 28px;position: relative;top: 5px;cursor:pointer;}.cur_exp{color:#FF6E1B;cursor:pointer;}.s_icon{margin:4px;}.like_badge {background: url(“http://static.tieba.baidu.com/tb/static-member/img/bg.png?v=1.0&#8243;) no-repeat scroll 0 0 transparent;height: 25px;line-height: 25px;line-height: 24px\9;_line-height: 24px;margin: 4px auto 0;position: relative;width: 85px;cursor:pointer;padding:0px;}.like_badge_title {color: #4C4C4C;font-family: arial,”宋体”;height: 25px;left: 0;top: 0;line-height: 25px;line-height: 28px\9;_line-height: 28px;position: absolute;text-align: center;width: 60px;margin-top:0px;margin-left:4px;}.like_badge_lv {color: #B65E00;font-family: arial;font-size: 11px;font-weight: bold;height: 25px;left: 60px;position: absolute;text-align: left;padding-left: 8px;width: 25px;}.badge_lv1 .like_badge_lv {background: url(“http://static.tieba.baidu.com/tb/static-member/img/s1.gif?v=1.0&#8221;) no-repeat scroll 0 0 transparent;margin-top:1px;}.badge_lv2 .like_badge_lv {background: url(“http://static.tieba.baidu.com/tb/static-member/img/s2.gif?v=1.0&#8221;) no-repeat scroll 0 0 transparent;padding-top:1px;}.badge_lv2_1 .like_badge_lv {background: url(“http://static.tieba.baidu.com/tb/static-member/img/s3.gif?v=1.0&#8221;) no-repeat scroll 0 0 transparent;padding-top:1px;}.badge_lv2_2 .like_badge_lv {background: url(“http://static.tieba.baidu.com/tb/static-member/img/s4.gif?v=1.0&#8221;) no-repeat scroll 0 0 transparent;padding-top:1px;}.badge_lv3 .like_badge_lv {background: url(“http://static.tieba.baidu.com/tb/static-member/img/s5.gif?v=1.0&#8221;) no-repeat scroll 0 0 transparent;padding-left: 4px;line-height: 20px;top: 1px;}.badge_lv3_1 .li、本文来源gao($daima.com搞@代@#码$网搞gaodaima代码ke_badge_lv {background: url(“http://static.tieba.baidu.com/tb/static-member/img/s6.gif?v=1.0&#8221;) no-repeat scroll 0 0 transparent;padding-left: 4px;line-height: 20px;top: 1px;}.badge_lv3_2 .like_badge_lv {background: url(“http://static.tieba.baidu.com/tb/static-member/img/s7.gif?v=1.0&#8221;) no-repeat scroll 0 0 transparent;padding-left: 4px;line-height: 20px;top: 1px;}.badge_lv4 .like_badge_lv {background: url(“http://static.tieba.baidu.com/tb/static-member/img/s8.gif?v=1.0&#8221;) no-repeat scroll 0 0 transparent;left: 58px;padding-left: 6px;padding-top: 4px;top: -3px;}.pt{cursor: pointer;}</style>

吧名 经验值 等级 取消关注
chrome 6960
gtabbs 5740
圣安地列斯 5096 我需要的内容就是这两个xx的内容,请问如何匹配

是对的啊

$str=file_get_contents('test.txt');$find='/href="\/f\?kw=([^"]*?)"\stitle="([^"]*?)"/s'; preg_match_all($find,$str,$res); echo "<pre class="prettyprint linenums">";print_r($res);echo "

“;/*Array( [0] => Array ( [0] => href=”/f?kw=chrome” title=”chrome” [1] => href=”/f?kw=gtabbs” title=”gtabbs” [2] => href=”/f?kw=%CA%A5%B0%B2%B5%D8%C1%D0%CB%B9″ title=”圣安地列斯” ) [1] => Array ( [0] => chrome [1] => gtabbs [2] => %CA%A5%B0%B2%B5%D8%C1%D0%CB%B9 ) [2] => Array ( [0] => chrome [1] => gtabbs [2] => 圣安地列斯 ))*/


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php正则匹配问题

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址