madrazel Posted April 23, 2007 Share Posted April 23, 2007 given is string: http://www.server.com/dir/dir2/dir3/file.html or myname@domain.com and result should be: http://www.server.com/dir/dir2/dir3/ or myname@ how to make it *really fast* without strrev and strstr ? Quote Link to comment https://forums.phpfreaks.com/topic/48358-what-is-the-fastest-method-to-extract-directory-from-url/ Share on other sites More sharing options...
MadTechie Posted April 23, 2007 Share Posted April 23, 2007 i guess without strrev and strstr, this will work <?php #$subject = "http://www.server.com/dir/dir2/dir3/file.html"; $subject = "myname@domain.com"; $result = eregi_replace('(.*@).*', '\\1', $subject); $result = eregi_replace('(.*\\/)(.*)[^\\/]+$', '\\1', $result); echo "$result<br />"; ?> Please note i am still learning eregi so am use them when i can, so this was kinda pratice for me Quote Link to comment https://forums.phpfreaks.com/topic/48358-what-is-the-fastest-method-to-extract-directory-from-url/#findComment-236445 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.