如何在 PHP 中获取 <b> 标签内的文本
How to get texts within the <b> tag in PHP
我搜索了很多 preg_match 表达式,但无法弄清楚。我想从下面的 <b>
标签中获取文本。
$string='<b>Joondanna
Investments Pty Ltd v The Minister for Lands, Planning and the Environment </b>(NTSC)
- discovery - judicial review - documents not relevant to question in
proceedings - application dismissed (C G)<br>';
preg_match( '/<b>(.*?)<\/b>/', $string, $match );
echo $match[1]; //Undefined offset error
您需要添加 's' 模式修饰符,以便点匹配所有内容,包括换行符
改变
preg_match( '/<b>(.*?)<\/b>/', $string, $match );
到
preg_match( '/<b>(.*?)<\/b>/s', $string, $match );
我搜索了很多 preg_match 表达式,但无法弄清楚。我想从下面的 <b>
标签中获取文本。
$string='<b>Joondanna
Investments Pty Ltd v The Minister for Lands, Planning and the Environment </b>(NTSC)
- discovery - judicial review - documents not relevant to question in
proceedings - application dismissed (C G)<br>';
preg_match( '/<b>(.*?)<\/b>/', $string, $match );
echo $match[1]; //Undefined offset error
您需要添加 's' 模式修饰符,以便点匹配所有内容,包括换行符
改变
preg_match( '/<b>(.*?)<\/b>/', $string, $match );
到
preg_match( '/<b>(.*?)<\/b>/s', $string, $match );