[英]Identify first character in a string
Hello I need help in identifying the first character of a string. 您好,我需要帮助来识别字符串的第一个字符。 if the string contains a forward slash "/" or no forward slash in php.
如果字符串中包含正斜杠“ /”或php中没有正斜杠。
Thanks in advance 提前致谢
Try this code: 试试这个代码:
<?php
function containSlash($str)
{
return substr($str, 0, 1) == "/";
}
// TEST
echo (containSlash("/hello") ? "TRUE" : "FALSE"); // TRUE
echo (containSlash("hello") ? "TRUE" : "FALSE"); // FALSE
?>
Try this 尝试这个
function getSlashes($str)
{
return $str[0] == '/' || $str[0] == '\\';
}
You're asking two different questions here. 您在这里问两个不同的问题。
You can examine the first character of a string using 您可以使用检查字符串的第一个字符
$str[0]
You can check whether a string contains no /
by using 您可以使用以下命令检查字符串是否不包含
/
strpos($str, '/') === FALSE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.