得到一切后的词 [英] Get everything after word

查看:43
本文介绍了得到一切后的词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以这个 Lorem Ipsum 文本为例:

Take this Lorem Ipsum text:

Lorem ipsum dolor 坐 amet,consectetur adipiscing 精英.Nulla felis diam, mattis id elementum eget, ullamcorper et purus.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla felis diam, mattis id elementum eget, ullamcorper et purus.

我如何使用 PHP 和正则表达式获得 Nulla 之后的所有内容?

How can I with PHP and regex get everything that comes after Nulla?

推荐答案

嗯,你不想使用一些简单的东西,比如:

Hmm you don't want to use some simple things like :

$str = substr($lorem, strpos($lorem, 'Nulla'));

如果您不想查找 Nulla,也不想查找 'null',您可以考虑使用 stripos 而不是 strpos...此代码将在返回值中包含 Nulla.如果您想排除 Nulla,您可能需要将它的 lentgh 添加到 strpos 值,即

if you do not want to look for Nulla, but also for 'null' you might consider using stripos instead of strpos... This code will include Nulla in the returned value. If you want to exclude Nulla, you might want to add it's lentgh to the strpos value i.e

$str = substr($lorem, strpos($lorem, 'Nulla') + 5);

最后,如果你需要一些更通用的东西,就像@Francis 建议的那样:

At last, if you need to have something a bit more generic, and as suggested @Francis :

$needle = 'Nulla'; 
$str = substr($lorem, strpos($lorem, $needle) + strlen($needle));

老实说,正则表达式对于这样的事情来说太过分了......

Honestly regexp are overkill for something like this...

这篇关于得到一切后的词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆