BR
asked on
Php string function
If my strings first two letters is "st" it's true otherwise it's false.
How can i do it with php?
How can i do it with php?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Working sample
<?php
$tests = array (
"street",
"sTreet",
"treet",
"sstreet",
"STREET",
"astreet",
"Street"
);
foreach($tests as $t) {
$caseins = (substr(strtolower($t),0,2) == 'st');
$casesen = (substr($t,0,2) == 'st');
if ($casesen) {
echo "Case Sensitive match on [<b>{$t}</b>]<br/>";
}
if ($caseins) {
echo "Case Insensitive match on [<b>{$t}</b>]<br/>";
}
if (!$caseins && !$casesen) {
echo "[<b>{$t}</b>] does not start with 'st'<br/>";
}
}
OutputCase Sensitive match on [street]
Case Insensitive match on [street]
Case Insensitive match on [sTreet]
[treet] does not start with 'st'
[sstreet] does not start with 'st'
Case Insensitive match on [STREET]
[astreet] does not start with 'st'
Case Insensitive match on [Street]
You are welcome.
ASKER
Wow, thank you
ASKER