Friday, 15 April 2011

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


I have an array with login data, where I want to remove different, user-defined stars, for example, my array Appears:

  array ([0] => Date: 16/03/2015 20:39 [1] => IP Address: 93.136.9 9.8 [2 ]  

What I want to do is, "Date:" from the first array element and "IP address" is removed from the second array element.

Now I Using str_replace:

  $ lastlogindate = str_replace ('Date:', 'Data: '$$ lastlogin [0]);  

But there is a better way to do this, and perhaps, and then with the tags, wrap the array in the array for each defined frequency in the element

You can also still use str_replace () Uses, but pass it to the array argument:

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

for input array:

  $ lastlogin = ['Date: 16/03/2015 20:39', 'IP address: 93.1 36.9 9 8 '];  

It gives you:

  Array ([0] => 16/03/2015 20:39 [1] = & gt; 93.136.9 9.8 9)  

No comments:

Post a Comment