-8

So let's say I have a String that looks like this: "apple, banana, orange". How do i split the text to get a Array that looks like this "apple", "banana", "orange". Thanks in advance.

Elias Konrad
  • 108
  • 1
  • 9
  • 2
    This is well-documented; have you tried anything so far? StackOverflow isn't a free code-writing service, and expects you to [**try to solve your own problem first**](http://meta.stackoverflow.com/questions/261592). Please update your question to show what you have already tried, showcasing the specific problem you are facing in a [**minimal, complete, and verifiable example**](http://stackoverflow.com/help/mcve). For further information, please see [**how to ask good questions**](http://stackoverflow.com/help/how-to-ask), and take the [**tour of the site**](http://stackoverflow.com/tour) :) – Obsidian Age Oct 05 '17 at 19:20
  • 1
    PHP provides the [`explode()`](http://php.net/manual/en/function.explode.php) function exactly for this purpose. And the [`trim()`](http://php.net/manual/en/function.trim.php) function to remove the unwanted whitespace characters from the beginning and end of a string. – axiac Oct 05 '17 at 19:22
  • 1
    Voted to close this because it's unlikely this question will be helpfull to anyone in the future. – icecub Oct 05 '17 at 19:32

1 Answers1

1

Use the explode PHP function :)

 <?php
    $str = "apple, banana, orange";
    print_r (explode(" ",$str));

 ?>
Andrew1996
  • 426
  • 1
  • 3
  • 15