- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Extract numbers after the last hyphen in PHP?
Let’s say the following is our string including hyphen and numbers as well −
"John-45-98-78-7898906756"
To extract numbers after – i.e. hyphen, use the concept of explode() with parameters - and $yourVariableName.
The PHP code is as follows −
Example
<!DOCTYPE html> <html> <body> <?php $values = "John-45-98-78-7898906756"; $values = explode("-",$values); $values = $values[4]; echo $values; ?> </body> </html>
Output
7898906756
- Related Articles
- MySQL query to remove numbers after hyphen in a VARCHAR string with numbers
- PHP preg_split with hyphen?
- Split a column after hyphen in MySQL and display the remaining value?
- extract() function in PHP
- REGEX in MySQL to display only numbers separated by hyphen.
- How to extract the last element in an R matrix?
- Fetch the substring after last dot in MySQL
- How to extract the last 4 characters from NSString?
- Splitting a hyphen delimited string with negative numbers or range of numbers - JavaScript?
- How to remove hyphen at last position from every value in R data frame column?
- How to set a string with hyphen and numbers in MySQL varchar?
- Select text after last slash in MySQL?
- Golang Program to extract the last two digits from the given year
- Haskell Program to extract the last two digits from the given year
- Product of the Last K Numbers in C++

Advertisements