PHP not removing spaces and showing wrong character length -


i have array of words retrieved database. looks (var_dump):

$description_array  = array(69) { [0]=> string(3) "out" [1]=> string(2) "of" .............  [44]=> string(5) " as" .................) 

the 44th element " as" has bit of white space before word.

i tried removing

foreach($description_array $value) {   $value = str_replace(" ", "", $value); } 

but results of have no effect on element. noticed " as" said have 5 characters. thought might new-lines or other special characters tried:

foreach($description_array $value) {   $value = str_replace("\n", "", $value); } 

and

foreach($description_array $value) {   $value = preg_replace('/\s\s+/', '', $value); } 

but neither of these commands achieved desired result. ideas, maybe i'm missing simple?

you can use array_map() , can use trim function in below

$array = array_map('trim',$your_array);  // wont work if have sub arrays 

or can modify code this

foreach($description_array $value) {    $arr[] = trim(preg_replace('/\s\s+/', '', $value)); } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -