Rogier schreef:explode is alleen wel een stuk minder snel dan preg_match.
Dat dacht ik ook, maar een testje:
[COLOR= #0000BB]<?php
$str[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]a,b[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$begin[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/microtime"]microtime[/URL][COLOR= #007700]([/COLOR]true[COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/for"]for[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$i[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #0000BB]$i[/COLOR] [COLOR= #007700]<=[/COLOR] [COLOR= #0000BB]1000000[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #0000BB]$i[/COLOR][COLOR= #007700]++)
{[/COLOR]
[COLOR= #0000BB]$v[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/explode"]explode[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000],[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$str[/COLOR][COLOR= #007700]);
}[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]explode: [/COLOR][COLOR= #007700].([/COLOR][URL="http://www.php.net/microtime"]microtime[/URL][COLOR= #007700]([/COLOR]true[COLOR= #007700]) -[/COLOR] [COLOR= #0000BB]$begin[/COLOR][COLOR= #007700]).[/COLOR][COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$begin[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/microtime"]microtime[/URL][COLOR= #007700]([/COLOR]true[COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/for"]for[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$i[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #0000BB]$i[/COLOR] [COLOR= #007700]<=[/COLOR] [COLOR= #0000BB]1000000[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #0000BB]$i[/COLOR][COLOR= #007700]++)
{[/COLOR]
[URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"@(.+?),(.+?)@is"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$str[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$v[/COLOR][COLOR= #007700]);
}[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]preg_match: [/COLOR][COLOR= #007700].([/COLOR][URL="http://www.php.net/microtime"]microtime[/URL][COLOR= #007700]([/COLOR]true[COLOR= #007700]) -[/COLOR] [COLOR= #0000BB]$begin[/COLOR][COLOR= #007700]).[/COLOR][COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];[/COLOR]
output:
explode: 2.3311731815338
preg_match: 4.8953850269318
(explode is dus 0,0000026 seconde sneller dan preg_match

)
Al is preg_match hier wel voor gemaakt inderdaad, dus wellicht is het beter om die te gebruiken. Maar explode vind ik veel intuïtiever werken; je ziet dan meteen wat je doet, en reguliere expressies snap ik na tig jaar nog steeds vrij weinig van; die dingen werken nooit bij mij.
En daarom doe ik eigenlijk alles met explode().

En ook al is explode misschien in sommige situaties trager; het scheelt ook weer geen seconden.