Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在<;b>;PHP中的标记_Php_Preg Match - Fatal编程技术网

如何在<;b>;PHP中的标记

如何在<;b>;PHP中的标记,php,preg-match,Php,Preg Match,我搜索了很多preg_match表达式,但没有找到这个。我想从以下位置获取标记内的文本 $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 - ap

我搜索了很多preg_match表达式,但没有找到这个。我想从以下位置获取
标记内的文本

$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
$string='Joondna
投资私人有限公司诉土地、规划和环境部长(NTSC)
-发现-司法审查-与问题无关的文件
诉讼-驳回申请(CG)
; preg_match(“/(.*?/”,$string,$match); echo$match[1]//未定义偏移误差
您需要添加“s”模式修改器,以便点匹配所有内容,包括换行符

改变

preg_match( '/<b>(.*?)<\/b>/', $string, $match );
preg_match(“/(.*?/”,$string,$match);

preg_match('/(.*?)/s',$string,$match);

整个匹配的字符串(包括html标记)将在0中,只有
(.*)
捕获的文本将在1中。为什么不使用html解析器来this@Ghost,我需要将结果插入数据库…@Nephil我指的是提取标记内文本的HTML解析器。得到文本后,继续下一步需要做的事情。
preg_match( '/<b>(.*?)<\/b>/s', $string, $match );