编程语言
首页 > 编程语言> > 使用PHP从另一个网站获取描述

使用PHP从另一个网站获取描述

作者:互联网

我正在尝试使用preg_match在网站上捕获此描述,只是出现问题:

这就是我要抓住的东西. < b>游戏说明之后的文字:< / b>< br />直至< b>工具v3.1信息:

<b>Game Description:</b><br />
Steel Diver is a new action-packed submarine combat game from Nintendo that<br />
immerses players in the 3D action with unique game controls and lush 3D<br />
environments. The player can choose from three different submarines, each<br />
with touch-screen control panels that players will have to master to guide<br />
them through treacherous undersea caverns while engaging enemy submarines,<br />
dodging depth charges and battling massive sea creatures. Steel Diver also<br />
takes advantage of the built-in gyroscope of the Nintendo 3DS system. The<br />
combination of 3D game play and one-of-a-kind controls makes for an immersive<br />
combination that must be experienced to be believed.<br />
<br />
<b>Tool v3.1 Info:

这是我尝试过的:

    $pattern1 = '#<b>Game Description:</b><br />\s*(.*?)\s*<b>Tool v3.1 Info:#';
    preg_match($pattern1,$downloadPage,$description);
    print_r($description);

$downloadPage只是使用curl打开URL,我已经获取了一些其他数据,只需要这部分的帮助.

谢谢

解决方法:

您需要s modifier才能匹配多行:

$pattern1 = '#<b>Game Description:</b><br />\s*(.*?)\s*<b>Tool v3.1 Info:#s';

Demo.

标签:preg-match,php
来源: https://codeday.me/bug/20191122/2059057.html