Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PHP – trim array

i have a string i made it an array

my string

1 S7-6544 S 07ЯНВ22 0105 ХДТ ГСВ OK SSTOW 1М A

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

my array

$d=explode(' ', $Session); 

my result

enter image description here

how can i do trim in array tell me please

>Solution :

You can use array_map('trim', $array) to trim all entries of the array.

$array = array_map('trim', $array);

Or, use preg_split() instead of explode :

$str = '1    S7-6544 S 07ЯНВ22 0105 ХДТ ГСВ OK  SSTOW                           1М   A';
$array = preg_split('~\s~', $str, 0, PREG_SPLIT_NO_EMPTY);
print_r($array)

Output:

(
    [0] => 1
    [1] => S7-6544
    [2] => S
    [3] => 07ЯНВ22
    [4] => 0105
    [5] => ХДТ
    [6] => ГСВ
    [7] => OK
    [8] => SSTOW
    [9] => 1М
    [10] => A
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading