Let's assume we have couple of inputs: 1-west:726435632:9236
2-west:8463758:873648
green:8234682:92347
red:98374:98374
H09
For output I want to have:
1. if it was anything other than H, just pass the first part like
1-west:283647873:86324873---->1-west
Can anybody help me how to implement this?
Something like this ?
function check($string) {
$test = preg_match('/^H./', $string);
if ($test) {
return 'HOLDING';
}
$parts = explode(':', $string);
return $parts[0];
}
Or in one line (assuming $input
contains your input)
$output = preg_match('/^H./', $input) ? 'HOLDING' : substr($input, 0, strpos($input, ":"));
Really don't need regex here -
foreach ($arrayOfStrings as $row)
{
(if substr($row, 0, 1) == "H")
{
echo "Holding";
} else {
echo substr($row, 0, strpos($row, ":"));
}
}