PHP str_starts_with()

📔 : PHP 🔗

str_starts_with() function check करता है कि क्या कोई String pass की गयी substring value से start हो रही है। match होने पर true return होता है otherwise false .

str_starts_with() function PHP version 8 में add किया गया था , इसलिए हो सकता है कि PHP के older version में error दे।

PHP str_starts_with Syntax

str_starts_with(string $haystack , $needle);
  1. string $haystack | required : string value जो हमें $needle string में check करनी है।

  2. string $needle | required : string value जिसमे हमें $haystack string check करनी है।

  3. Return Value : Boolean value true / false return होता है।

PHP str_starts_with Example

File : php_str_starts_with.php

Copy Fullscreen Close Fullscreen
	$str = "learnhinditutscom";
	if (str_starts_with($str, "learn")) echo "$str starts with learn. <br>";
	if (str_starts_with($str, "Learn")) echo "$str starts with Learn.";
	/*now try with empty string*/
	if (str_starts_with("", $str)) echo "$str starts with empty string";
	if (str_starts_with("", "")) echo "empty string starts with empty string";
learnhinditutscom starts with learn.
empty string starts with empty string

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook