john john john john - 2 months ago 6
PHP Question

how to trim white space in array in php

I have an array which contains some words. I want to get all words as unique part. so when I come to a whitespace , it's broken to a new. I mean , finally I want something like this:


first I want to explode it , then trim
between words . this is my code but unfortunately doesn't work.
Aug 20
come together. I want them individually.

$firs_arr=new array();
$first_arr='Aug 20, 2016 ';


If you call your source $source, then $result below is the array you want:

//split into parts separated by all non-word characters
$result = preg_split('/\W+/',trim($source));

Live demo