Jump to content

replace everything except...


Julius

Recommended Posts

But what works faster: :alnum: or all given values?

 

Running this, I'm not seeing a difference.

 

$start=time();
$string='http://www.whatever.com?12()$%^*&';
for ($i=0;$i<1000000;$i++)
$url=preg_replace('#[^/[:alnum:]_-]#','',$string);
$lap=time();
for ($i=0;$i<1000000;$i++)
$url=preg_replace('#[^/0-9a-zA-Z_-]#','',$string);
$end=time();
$time1= $lap - $start;
$time2= $end - $lap;
echo $time1."<br />";
echo $time2."<br />";

 

Output:

6

6

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.