1LT John W. Holmes wrote:

Assuming $url is what you have above:

$tilde = strpos($url,"~");
$slash = strpos($url,"/",$tilde);
$length = $slash - $tilde;

$username = substr($url,$tilde,$length);

Or you can use a regular expression, but the above is probably faster.

preg_match("!(~[^/]*)/!",$url,$match);
or
preg_match("!(~.*)/!U",$url,$match);

In my tests, the first solution (using strpos) was the fastest by 35%.

---John Holmes...


Hi John,
Ive been very interested to note that you seem to have a very keen idea of the relative speed of different functions.

I wonder if you could pass on some pointers for speed testing.

thanks

--

Sean


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to