I try to find out if the first char of a string is a slash.
I have this string /var/www/html
$mystring = "/var/www/html";
$test = preg_match("/^/[.]/", $mystring);
if ($test == 1)
{
echo "ret = 1";
}
else
{
echo "ret = 0";
}
But I always get ret = 0
.
Try this:
<?php
$mystring = "/var/www/html";
$test = preg_match("/^\//", $mystring);
if ($test == 1)
{
echo "ret = 1";
}
else
{
echo "ret = 0";
}
You can simply use strpos()
for that:
<?php
$mystring = "/var/www/html";
if(strpos($mystring,"/") === 0){
echo "ret = 1";
}else{
echo "ret = 0";
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With