How can I check if the first 2 characters of an array are 0x? here is an example:
$hex = "0xFFFF";
if($hex[0:2].find('0x')==0)
{
print("0x Found.");
}
else
{
print("0x Not Found.");
}
Can anyone create an alternative that works?
Using strnicmp (manual) looks good.
$hex = '0xFFFF';
if (strnicmp($hex, '0x', 2) == 0)
{
print("0x Found.");
}
else
{
print("0x Not Found.");
}
Looks for an insensitive '0x' string at the beginning of your $hex var.
$hex = '0xFFFF';
if ($hex[0].$hex[1] == '0x')
{
print("0x Found.");
}
else
{
print("0x Not Found.");
}
Without needing to use any function. See this page for it's usage.
You can access string characters as an array to get the first and second index and check if they are 0 and x.
<?php
$hex = array("0xFFF","5xFFF","0xDDD");
$len = count($hex);
$msg = "";
for ($i = 0; $i < $len; $i++) {
if ($hex[$i][0] == "0" && $hex[$i][1] == "x") {
$msg .= $hex[$i] . ' starts with 0x!' . "\n";
}
}
echo ($msg);
?>
$hex[0:2]- PHP does not have nice stuff like that. Consider using Python if you like having a nice operator to get a slice from a string.