- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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
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>
This will produce the following output
Array (  => Array (  => java  => php  => hibernate  => php )  => Array (  => java  => php  => hibernate  => php ) )
- Java Program to split a string with dot
- How to Split a String with Escaped Delimiters?
- PHP program to split a given comma delimited string into an array of values
- Split String with Dot (.) in Java
- Split String with Comma (,) in Java
- Split a string in Java
- Split string into sentences using regex in PHP
- How to split a string with a string delimiter in C#?
- Split a string and loop through values in MySQL Procedure?
- How to split a string in Java?
- How to split a string in Python
- How to split a string in Golang?
- MySQL query to split a column after specific characters?
- Split a string during MongoDB aggregate
- How to split a Java String into tokens with StringTokenizer?