- 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 ends with given word in PHP
Create a function to check whether a string ends with the specified string or not. The function should return TRUE on success or FALSE on failure.
The following is the syntax −
endFunc(str, lastStr)
Consider the following parameters in it to check −
str − The string to be tested
lastStr − The text to be searched in the end of the specified string.
Example
The following is an example −
<?php function endFunc($str, $lastString) { $count = strlen($lastString); if ($count = = 0) { return true; } return (substr($str, -$count) = = = $lastString); } if(endFunc("pqrstuv","rst")) echo "True!"; else echo "False!"; ?>
Output
The following is the output −
False!
- Related Articles
- Check if a string starts with given word in PHP
- Check if string ends with desired character in JavaScript
- How to check if a string ends with a specified Suffix 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 ends with suffix in Python?
- How to check if the string ends with specific substring in Java?
- Check whether a string ends with some other string - JavaScript
- MySQL query to check if a string contains a word?
- How to check if a string contains a certain word in C#?
- Check if a given string is sum-string in C++
- Check if a String starts with any of the given prefixes in Java
- Python Check if suffix matches with any string in given list?
- Check if given words are present in a string
- How to check if the string contains the specific word?
- How to check if a given word is a Python keyword or not?

Advertisements