
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
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 ) )
- Related Articles
- PHP preg_split with hyphen?
- PHP program to split a given comma delimited string into an array of values
- How to split a string with a string delimiter in C#?
- How to Split a String with Escaped Delimiters?
- Java Program to split a string with dot
- Split string into sentences using regex in PHP
- Update all the values of a field with a specific string in MongoDB?
- Split a string and loop through values in MySQL Procedure?
- Fetch a specific record from a column with string values (string, numbers and special characters) in MySQL
- PHP fetch a specific value that begins with a given number from a string with letters and numbers?
- How to split a Java String into tokens with StringTokenizer?
- Python program to split a string and join with comma
- How to split string values that contain special characters in R?
- Split String with Dot (.) in Java
- Split String with Comma (,) in Java

Advertisements