drudfe0446838 2015-06-26 09:56 采纳率: 0%
浏览 46
已采纳

Regex PHP:从其他网站获取特定内容

I'm writing a PHP script that will fetch specific codes from the other site.

All is done and its fetching a div which has a class and showing it on my page.

$title = '#\<div class="detailBox"\>(.+?)\<\/div\>#s';
preg_match($title, $page, $titles);
echo $titles[0];

But when I try to fetch from a table it shows nothing

The content on the other site is like this:

<tr>
   <th scope="row">開催時間</th>
   <td>10:30~17:00</td>
</tr>

And I'm using this code to fetch it:

$date = '#\<tr\><th scope="row"\>開催時間<\/th\><td\>(.+?)\<\/td\><\/tr\>#s';
preg_match($date, $page, $dates);
echo $dates[0];

I have tried $date = '#\<th scope="row"\>開催時間<\/th\>#s'; and it works but not if I add <td> in it.

What I'm doing wrong?

  • 写回答

2条回答 默认 最新

  • dsm1998 2015-06-26 10:02
    关注

    You need to turn on the unicode modifier u and also match the inbetween line breaks.

    $date = '#<tr>\s*<th scope="row">開催時間</th>\s*<td>(.+?)</td>\s*</tr>#su';
    preg_match($date, $page, $dates);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决