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
**
But your supervisor recommended what in place of
explode()
? Regular expressions (depending on the task)?preg_split()
? Dude, it goes fromexplode()
even. See: https://stackoverflow.com/questions/27303235/in-php-which-is-faster-preg-splitor-explode– Fabiano Monteiro
In this case the goal is to locate a specific part of a string , for this he asked me to use strrpos and substar .
– Thiago
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– Fabiano Monteiro
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.
– Thiago