Textarea input to Array elements

I wants to generate an array with different elements depending on how many words are written in the text-area. Every single word from the text-area should be in their own element in my Array. I have been googling this without any success and therefore want to try my luck here.

Could look something like this

 ----  input: "Hello I love stack overflow" ----- 

Output:

 Array ( [0] => Hello [1] => I [2] => love [3] => stack [4] => overflow [5]) 

Upvotes: 0

Views: 352

Answers (3)

Anjan Kumar Dhali
Anjan Kumar Dhali

Reputation: 1

 <?php
  $string="Welcome to CodeNair";
  // explode('separator',$string)
  $array=explode(' ',$string);
 print_r($array);
 //Output : Array ( [0] => Welcome [1] => to [2] => CodeNair )
 ?>

Upvotes: 0

Aefits
Aefits

Reputation: 3469

User explode:

<?php

    $pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";
    $pieces = explode(" ", $pizza);
    echo $pieces[0]; // piece1
    echo $pieces[1]; // piece2

Upvotes: 0

Exprator
Exprator

Reputation: 27513

$output = explode(' ',$input);

then

print_r($output);

then access each by

$output[0],
$output[1],

and so on

Upvotes: 1

Related Questions