Doubt about the Explode -PHP function

0

After I develop a new feature on the system my supervisor asked me not to use the EXPLODE function because it consumes a lot of memory on the server.

Does the function explode and really suck to work with a lot of requests? if yes what function can replace it?

    
asked by anonymous 14.03.2018 / 12:32

1 answer

0

There are two types in php explode() and preg_split() Below you can see the difference between the two

In a simple use explode () is much faster,

But preg_split has the advantages of using the tab (\ t) character and space Space with \ s. and also can use regex to divide into several sections, which can make it heavier

The metacharacter \ s is used to find a blank character

In this case you can see which best to use in your follow up.

One tip, use array_filter to delete empty items in your return array

Example:

$keyword = explode(' ', $_GET['search']); //or preg_split
print_r($keyword);

$keyword = array_filter($arr, 'empty');
print_r($keyword);

**

  

forum references

p>

**

    
14.03.2018 / 12:39