Check if a String Starts With a Specified String in PHP

//php check if first four characters of a string = http
substr( $http, 0, 4 ) === "http";
//php check if first five characters of a string = https
substr( $https, 0, 5 ) === "https";

3
1
Awgiedawgie 440220 points

                                    phpCopy<?php
  $string = "Mr. Peter";
  if(substr($string, 0, 3) === "Mr."){
      echo "The string starts with the desired substring.";
  }else 
      echo "The string does not start with the desired substring.";
?>

3 (1 Votes)
0
3.43
7
A-312 69370 points

                                    phpCopy<?php
  $string = "Mr. Peter";
  if(strncmp($string, "Mr.", 3) === 0){
      echo "The string starts with the desired substring.";
  }else 
      echo "The string does not start with the desired substring.";
?>

3.43 (7 Votes)
0
4
4
Awgiedawgie 440220 points

                                    phpCopy<?php
  $string = "mr. Peter";
  if(strncasecmp($string, "Mr.", 3) === 0){
      echo "The string starts with the desired substring.";
  }else 
      echo "The string does not start with the desired substring.";
?>

4 (4 Votes)
0
4
1
Phoenix Logan 186120 points

                                    phpCopy<?php
  $string = "Mr. Peter";
  if(strpos( $string, "Mr." ) === 0){
      echo "The string starts with the desired substring.";
  }else 
      echo "The string does not start with the desired substring.";
?>

4 (1 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
php check string starts with php regex string starts with php check if string begins with substring find if string starts with char php php check if a string starts with php if string start by php check is string start with if string starts with php php str_starts_with check if string start with php check if string begins with php php check if text starts by php check if string starts with character str starts with php equivalent php string starts with php7 php check starts php check if string starts with 10 numbers php check if string starts with number php regex check if string starts with php string starts with substring check starts with in php php search if string starts check if string starts with a letter php php chack if string starts with text starts with php check if a string starts with a substring php php if string starts with check string starts with specific string php str_starts_with php 7 str_starts_with php if string start with string php string startswith php 7 check if string starts with x php php how to check if string starts with specific characters php how to check if string starts with php to find letter startswith how to check if a string starts with a substring in php number string starts with string php check if string starts with a character php check if string starts with number php php if string begins with check if string startswith php php check if string begins with php string starts with php check if string starts with php string starts with php 7 string starts with php check if string starts with php string starts with in php php if starts with
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source