ted_chou12 Posted October 19, 2009 Share Posted October 19, 2009 Hi, I seem to be confused about the strstr function, eg. i have a string like: "a.b.c.d.e.f" "a.b.c.d.e" I always want it to split at the second "." from the end, so resulting in: "e.f" "d.e" respectively etc... Please feel free to ask me if you don't understand. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/178179-solved-hi-explode-and-strstr/ Share on other sites More sharing options...
btherl Posted October 19, 2009 Share Posted October 19, 2009 Is this for processing domain names? strstr() cannot choose the second "." from the end. It matches simple string patterns only. An alternative is to explode() on ".", count() the number of items in the array, take the last two items from the array and implode() them again using ".". Or you can explode(), reverse the array, take the first two items, reverse again and then use implode(). That's not as fast but some people like that approach because there's no arithmetic Another approach is using a regexp, which is able to specify rules like "take the last two items seperated by dots". Also if you are processing domain names, be aware of issues with country level domain names. Some are two levels and some are three levels, and some countries even mix both two and three level. Quote Link to comment https://forums.phpfreaks.com/topic/178179-solved-hi-explode-and-strstr/#findComment-939486 Share on other sites More sharing options...
ted_chou12 Posted October 19, 2009 Author Share Posted October 19, 2009 Thanks, I see, then ill stick with explode() and use count ps. im trying to read the directory file, cause this file has two extensions, so i was thinking if strstr could give a better result then multiple functions combined, thanks Quote Link to comment https://forums.phpfreaks.com/topic/178179-solved-hi-explode-and-strstr/#findComment-939522 Share on other sites More sharing options...
Daniel0 Posted October 19, 2009 Share Posted October 19, 2009 I believe that for filenames, everything past the first dot is considered the extension. You needn't worry about parsing paths though. There is a function called pathinfo that does this for you. Quote Link to comment https://forums.phpfreaks.com/topic/178179-solved-hi-explode-and-strstr/#findComment-939528 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.