Link to home
Start Free TrialLog in
Avatar of BR
BRFlag for Türkiye

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?
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BR

ASKER

Thank you
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/>";
  }
}

Open in new window

Output
Case 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]

Open in new window

You are welcome.
Avatar of BR

ASKER

Wow, thank you