php - How to search and remove various string in array elements? -


i have array login data, need remove various, user defined strings, example, array looks like:

array ( [0] => date: 16/03/2015 20:39 [1] => ip address: 93.136.99.89 [2] 

what want remove "date:" first array element , "ip address" second array element.

now using str_replace:

$lastlogindate = str_replace('date:', 'datum:', $lastlogin[0]); 

but there more elegant way of this, , maybe, find defined occurance, , wrapp tag, every defined occurance in string in array element?

you can still use str_replace(), pass array arguments it:

$lastlogindate = str_replace(array('date: ', 'ip address: '), '', $lastlogin); 

for input array:

$lastlogin = ['date: 16/03/2015 20:39', 'ip address: 93.136.99.89']; 

it returns you:

array ( [0] => 16/03/2015 20:39 [1] => 93.136.99.89 ) 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -