我试图在 PHP 活动系统中获取元内容,问题是它提供的内容为
admin 2 天,2 小时前写了一个新帖子,FIRE
所以在这我想字“火”,但因为它的标题将是动态的,所以我能做的就是找到这个词的帖子,因为这将是共同所有,所以我可以后,即可获取下一个单词post,,如果post,IS展示。谁能建议我如何做到这一点?假设我们还有一个这样的内容
管理员在 2 天 3 小时前发布了更新
它没有,post,所以它会被避免。
使用正则表达式
$string="admin wrote a new post, FIRE 2 days, 2 hours ago";
$result=preg_split('/post,/',$string);
if(count($result)>1){
$result_split=explode(' ',$result[1]);
print_r($result_split[1]);
}
Run Code Online (Sandbox Code Playgroud)
这一个输出 FIRE
其它的办法
$string="admin wrote a new post, FIRE 2 days, 2 hours ago";
$result=preg_match_all('/(?<=(post,))(\s\w*)/',$string,$matches);
print_r($matches[0]);
Run Code Online (Sandbox Code Playgroud)