【发布时间】:2020-12-24 20:43:00
【问题描述】:
我正在创建一个正则表达式 https://www.phpliveregex.com/#tab-preg-match
代码如下:
$input_line = 'Sector(s) : Basic Materials Industry : Gold Full-time employees : ';
preg_match('/Industry : (.*) Full-time employees :/', $input_line, $output_array);
在在线工具中,结果符合预期,即“Gold”。
但是在我的代码中这并没有发生:
echo preg_match('/Industry : (.*) Full-time employees :/', $arr[5], $industry_arr);
返回 0。
数组 $arr 如下所示:
Array ( [0] => [1] => [2] => [3] => [4] => [5] => Sector(s) : Basic Materials Industry : Gold Full-time employees : [6] => [7] => )
在开发人员工具中,我的数组看起来像这样,我很困惑:
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] => Sector(s) : Basic Materials
Industry : Gold
Full-time employees :\
[6] =>
[7] =>
)
如果我执行 echo $arr[5] 我会得到以下信息:
Sector(s) : Basic Materials Industry : Gold Full-time employees :
我想知道非中断空间是否在这里引起了问题?
提前致谢
【问题讨论】:
-
试试
echo $arr[5],然后在你的问题中包含这个。
标签: php regex preg-match screen-scraping