Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJohn Weland
42,478 PointsCheck if a string ends with an item in an array
So I am looping over a massive array of user accounts.
I am getting the UserAccount email as $email
I need to check if the value after the last '.' matches my array of valid TLDs. So if my email is john.weland@example.com, find the last "." and compare it to a array of valid TLDs in this case COM is in that list. so it should be valid.
However john.weland@example.coma, coma is not in that array thus it should be invalid.
I made this list of TLDs in to an array.
1 Answer
Ted Sumner
Courses Plus Student 17,967 PointsI think this is what you want: http://php.net/manual/en/function.strrchr.php. I trust you can write the comparison script.