Q:

How to split a string into an array in PHP

0

How to split a string into an array in PHP

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the PHP explode() function

You can use the PHP explode() function to split or break a string into an array by a separator string like space, comma, hyphen etc. You can also set the optional limit parameter to specify the number of array elements to return. Let's try out an example and see how it works:

<?php
$my_str = 'The quick brown fox jumps over the lazy dog.';
print_r(explode(" ", $my_str));
echo "<br>";
print_r(explode(" ", $my_str, 4));
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to combine two strings in PHP... >>
<< How to create a string by joining the values of an...