[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Php string function

Posted on 2016-10-24
5
Medium Priority
?
48 Views
Last Modified: 2016-10-24
If my strings first two letters is "st" it's true otherwise it's false.

How can i do it with php?
0
Comment
Question by:Braveheartli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 59

Accepted Solution

by:
Julian Hansen earned 2000 total points
ID: 41857546
Case sensitive
$result = (substr($str,0,2) == 'st');

Open in new window

Case insensitve
$result = (substr(strtolower($str),0,2) == 'st');

Open in new window

0
 
LVL 1

Author Closing Comment

by:Braveheartli
ID: 41857551
Thank you
0
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 41857555
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

2
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 41857556
You are welcome.
0
 
LVL 1

Author Comment

by:Braveheartli
ID: 41857559
Wow, thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question