- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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!
- Related Articles
- Check if a string ends with given word in PHP
- Check if a String starts with any of the given prefixes in Java
- How to check if a string starts with a specified Prefix string in Golang?
- Find if a string starts and ends with another given string in C++
- How to check if string or a substring of string starts with substring in Python?
- Python Program to check if a string starts with a substring using regex
- Java Program to check if any String in the list starts with a letter
- How to check whether a string starts with XYZ in Python?
- MySQL query to check if a string contains a word?
- Golang Program to check a string starts with a specified substring
- How to check if a string contains a certain word in C#?
- Check if a given string is sum-string in C++
- Python Check if suffix matches with any string in given list?
- Check if a number N starts with 1 in b-base in C++
- Return TRUE if the first string starts with a specific second string JavaScript

Advertisements