PHP Subtract First Character of String

我怕爱的太早我们不能终老 提交于 2019-12-29 01:43:10

问题


I know this is simple, and I've done it before, but I've forgotten how to do it.

How might I, in php, subtract the first letter of a string?

For example:

FOOBAR would become OOBAR

I think its something like $string[-1];


回答1:


substr($string, 1)

http://php.net/manual/en/function.substr.php




回答2:


substr ( $string , 1 ,strlen($string) )




回答3:


If you are echoing the string out, then use:

$string[0] = '';

It's over an order of magnitude faster than:

substr($string, 1);

However, for anything else (eg accessing a database) it can cause problems and should be avoided.



来源:https://stackoverflow.com/questions/3592000/php-subtract-first-character-of-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!