- 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
PHP fetch a specific value that begins with a given number from a string with letters and numbers?
Let’s say the following is our string with letters and numbers −
$value ="1045632245555fghjklm67535454663443gfdjkbvc9890000006777743";
We ant a specific value beginning from 989 i.e.−
9890000006777743
Example
For this, use substr() along with strpos().
<!DOCTYPE html> <html> <body> <?php $value ="1045632245555fghjklm67535454663443gfdjkbvc9890000006777743"; echo "The actual value is=",$value,"<br>"; $result=substr($value, strpos($value,"989"), 16); echo "The filter value is=",$result; ?> </body> </html>
Output
The actual value is=1045632245555fghjklm67535454663443gfdjkbvc9890000006777743 The filter value is=9890000006777743
Advertisements