php – 如何从HTML中的所有标签之间获取数组中的文本?
发布时间:2020-12-13 13:15:10 所属栏目:PHP教程 来源:网络整理
导读:我想在所有 span之间的数组中获取文本. /跨度标签从 HTML,我尝试过这个代码,但它只返回一个事件: preg_match('/span(.+?)/span/is',$row['tbl_highlighted_icon_content'],$matches);echo $matches[1]; 我的HTML: spanThe wish to/span be unfairly treat
我想在所有< span>之间的数组中获取文本. < /跨度>标签从
HTML,我尝试过这个代码,但它只返回一个事件:
preg_match('/<span>(.+?)</span>/is',$row['tbl_highlighted_icon_content'],$matches); echo $matches[1]; 我的HTML: <span>The wish to</span> be unfairly treated is a compromise attempt that would COMBINE attack <span>and innocen</span>ce. Who can combine the wholly incompatible,and make a unity of what can NEVER j<span>oin? Walk </span>you the gentle way, 我的代码仅返回一次span标签,但是我想要以HTML格式从php数组的形式获取每个span标签中的所有文本.
您需要切换到
preg_match_all功能
码 $row['tbl_highlighted_icon_content'] = '<span>The wish to</span> be unfairly treated is a compromise attempt that would COMBINE attack <span>and innocen</span>ce. Who can combine the wholly incompatible,and make a unity of what can NEVER j<span>oin? Walk </span>you the gentle way,'; preg_match_all('/<span>.*?</span>/is',$matches); var_dump($matches); 正如你可以看到的,数组是正确填充的,所以你可以回应所有的匹配 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |