如何获得某个角色后的一切? [英] How to get everything after a certain character?

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

问题描述

我有一个字符串,我想在得到一定值后得到所有东西.字符串始终以一组数字开头,然后是下划线.我想在下划线之后得到字符串的其余部分.因此,例如,如果我有以下字符串以及想要返回的内容:

I've got a string and I'd like to get everything after a certain value. The string always starts off with a set of numbers and then an underscore. I'd like to get the rest of the string after the underscore. So for example if I have the following strings and what I'd like returned:

"123_String" -> "String"
"233718_This_is_a_string" -> "This_is_a_string"
"83_Another Example" -> "Another Example"

我该如何做这样的事情?

How can I go about doing something like this?

推荐答案

strpos() 查找以下项的偏移量下划线,然后substr将从该索引加1开始获取所有内容.

The strpos() finds the offset of the underscore, then substr grabs everything from that index plus 1, onwards.

$data = "123_String";    
$whatIWant = substr($data, strpos($data, "_") + 1);    
echo $whatIWant;


如果您还想在尝试获取字符串中是否存在下划线字符(_),可以使用以下命令:


If you also want to check if the underscore character (_) exists in your string before trying to get it, you can use the following:

if (($pos = strpos($data, "_")) !== FALSE) { 
    $whatIWant = substr($data, $pos+1); 
}

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

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