如何检查字符串是否以"_"开头在PHP中? [英] How to check if a string starts with "_" in PHP?
本文介绍了如何检查字符串是否以"_"开头在PHP中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例:我有一个$variable = "_foo"
,并且我想绝对确保$ variable不会以下划线"_"
开头.如何在PHP中做到这一点?可以在字符串后面访问char数组吗?
Example: I have a $variable = "_foo"
, and I want to make absolutely sure that $variable does not start with an underscore "_"
. How can I do that in PHP? Is there some access to the char array behind the string?
推荐答案
您可能会签出php中的substr
函数并以这种方式获取第一个字符:
You might check out the substr
function in php and grab the first character that way:
http://php.net/manual/zh/function.substr.php
if (substr('_abcdef', 0, 1) === '_') { ... }
这篇关于如何检查字符串是否以"_"开头在PHP中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文