Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove "<" and ">" tags from an array in php

Tags:

string

php

I have an array like this:

Array
(
    [0] => "<[email protected]>"
    [1] => "<[email protected]>"
    [2] => "<[email protected]>"
)

Now I want to remove "<" and ">" from above array so that it look like

Array
(
    [0] => "[email protected]"
    [1] => "[email protected]"
    [2] => "[email protected]"
)

How to do this in php? Please help me out.

I'm using array_filter(); is there any easier way to do that except array_filter()?

like image 541
diEcho Avatar asked Jul 24 '26 04:07

diEcho


1 Answers

You could take an array_walk on it:

// Removes starting and trailing < and > characters

 function trim_gt_and_lt(&$value) 
{ 
    $value = trim($value, "<>"); 
}

array_walk($array, 'trim_gt_and_lt');

Note however that this will also remove starting > and trailing < which may not be what you want.

like image 106
Pekka Avatar answered Jul 25 '26 19:07

Pekka