Doubt about the function Explode -PHP

Asked

Viewed 106 times

1

After I developed a new functionality in the system my supervisor asked me not to use the EXPLODE function because it consumes large amount of memory on the server.

The function explodes and really so bad to work with a lot of requests? if yes which function can replace it?

  • But your supervisor recommended what in place of explode()? Regular expressions (depending on the task)? preg_split()? Dude, it goes from explode() even. See: https://stackoverflow.com/questions/27303235/in-php-which-is-faster-preg-splitor-explode

  • In this case the goal is to locate a specific part of a string , for this he asked me to use strrpos and substar .

  • You can use explode yes. It would be interesting if you edit your question and put the code. But the use of explode(), still makes sense in this case. See the second most voted response, the use of the explode: https://stackoverflow.com/questions/17030779/splitting-strings-in-php-and-get-last-part

  • Thank you very much, but one thing has not yet become clear to me , Explode() remains viable even with a large number of requests? Because as I said, my supervisor used as an argument that this function consumes a lot of memory when it receives a heavy number of requests.

1 answer

0

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

In a simple use explodes() is much faster,

But preg_split has the advantages of using the tab (\t) and space Space with s. and also be able to 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 one to use in your follow-up.

One hint, 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 in English

**

Browser other questions tagged

You are not signed in. Login or sign up in order to post.