PHP preg_split to split a string with specific values?

PHPServer Side ProgrammingProgramming

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 

 Live Demo

<!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 ) )
raja
Published on 13-Oct-2020 07:18:54
Advertisements