
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check If a String Starts with Given Word in PHP
Create a function to check whether a string begins with the specified string or not. The function should return TRUE on success or FALSE on failure.
The following is the syntax −
begnWith(str, begnStr)
Consider the following parameters in it to check −
str − The string to be tested
begnStr − The text to be searched in the beginning of the specified string.
Example
The following is an example −
<?php function begnWith($str, $begnString) { $len = strlen($begnString); return (substr($str, 0, $len) = = = $begnString); } if(begnWith("pqrstuvwxyz","p")) echo "True! It begins with p!"; else echo "False! It isn't beginning with p!"; ?>
Output
The following is the output −
True! It begins with p!
Advertisements