- 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 preg_split to split a string with specific values?
For this, use preg_match_all(). Let’s say the following is our string
$values = 'javamysqlphpmongodbpythonspringhibernatephp';
We want to split with specific values like
java hibernate php
Example
The PHP code is as follows
<!DOCTYPE html> <html> <body> <?php $values = 'javamysqlphpmongodbpythonspringhibernatephp'; $afterSpliting = preg_match_all("/(java|hibernate|php)/", $values, $result); print_r($result); ?> </body> </html>
Output
This will produce the following output
Array ( [0] => Array ( [0] => java [1] => php [2] => hibernate [3] => php ) [1] => Array ( [0] => java [1] => php [2] => hibernate [3] => php ) )
Advertisements