- 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
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
Advertisements