Jump to content

Recommended Posts

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!)

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.