elite_prodigy Posted April 13, 2009 Share Posted April 13, 2009 Basically, I need to get a series 0f domains out of a string and store them in an array where they will then be cross-checked on another array, but the details after I get the domain are not nearly as important as getting the domain itself. I've included a sample of what I would have to extract. (Posting the real data would feel too much like advertising to me and would thus feel tacky.) sub.domain.com: username abc.alphabet.com: qwerty example.com: bob google.com: qwerty mydomain.org: jose cia.gov: obama *: root I don't care about anything after the ":" (colon), of course I could explode() the string, and cycle through the array and add every other index to the new array, but that just seems messy to me. I was wondering if there is a function I've missed, or if I'm over-thinking things. I don't expect anyone to write the function for me, I won't stop you if you want to because I can't, an example would be nice, but a simple explanation of the method to use would be awesome and highly apreciated. -David (As always, you guys truly do rock!) Link to comment https://forums.phpfreaks.com/topic/153922-solved-the-best-way-to-extract-data-from-a-string/ Share on other sites More sharing options...
laffin Posted April 13, 2009 Share Posted April 13, 2009 a bunch of ways to do this strpos & substr find the colon, and grab everything before it preg_match, wud match the pattern of yer query, but it creates a new set of arrays I believe the pattern for preg match wud be '@(.*?)\:.*@' but the strpos method is faster Hope that helps Link to comment https://forums.phpfreaks.com/topic/153922-solved-the-best-way-to-extract-data-from-a-string/#findComment-809015 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.