w3resource
php Programming Exercies

PHP String Exercises: Split a string

PHP String: Exercise-2 with Solution

Write a PHP script to split the following string.

Sample string : '082307'

Pictorial Presentation:

PHP String Exercises: Split a string

Sample Solution:

PHP Code:

<?php
$str1= '082307'; 
echo substr(chunk_split($str1, 2, ':'), 0, -1)."\n";
?>

Sample Output:

08:23:07

Flowchart :

Flowchart: Split a string

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a PHP script to transform a string all cases of letters or words
Next: Write a PHP script to check if a string contains a specific string?

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming