Re: Substr
| From: | M. Sokolewicz | Date: | Mon, 25 Oct 2004 13:39:28 +0000 |
| Subject: | Re: Substr | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-200248@lists.php.net to get a copy of this message | ||
split() uses the POSIX regular expressions engine, and thus also uses regular expressions. The loading of this engine is a massive overhead when dealing with simple splitting of a string. To do basic things like this it's a lot faster to use explode().
- Tul
Francisco M. Marzoa Alonso wrote:
You can also use split function if you do not know about regular expressions and do not want to learn: <?php $string = "pid_1_date_2004_10_25"; $regs = split ("_", $string ); print_r ($regs); ?> I think its autoexplicative. Shaun wrote:Hi, I have a string as follows: pid_1_date_2004_10_25 pid tells me the Project_ID and date tells me the date(!). I need to extract this information from the string so to get the date I need everything after 'date_' as follows: substr(strstr($key, 'date_'), 4) However, to get the Project ID I need to extract everything after 'pid_' and everything before 'date_'. Can someone help me with this please as PHP doesn't seem to provide a function for extracting information from a string that occurs before the 'needle'?