WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to split a string into an array in PHP

Topic: PHP / MySQLPrev|Next

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.

  • <?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));
  • ?>

Related FAQ

Here are some more FAQ related to this topic:

Your Feedback:

We would love to hear from you, please drop us a line.