I have a “blacklist” of all disallowed websites. The blacklist is stored in a CONF (“configuration”) array and each website is separated by a line break ("
"). To see if a website is in the blacklist I run this code:
$blacklisted = explode("\
", $bwclass->conf['website_blacklist']);
if (in_array($mywebsitevar, $blacklisted))
{
echo 'You have been blacklisted.';
}
Here’s the thing. If a user enters in “http://mysite.com” as their website and “mysite.com” is in the blacklist, it won’t match. Why? Because the URL in the blacklist isn’t containing the http://. So, my question is, is there an array function that you can run to see if a string is contained WITHIN each element of an array? It’s like in_array, except just not an exact match. Is there anyway you know how to do this without doing a foreach() and ereg() on each element in an array?
Not that I know of. But don’t be afraid to write your own. Predefined functions are great, but they don’t cover everything. Just do like you said and write a foreach loop. Though, I’ll recommend forgetting ereg and using preg because it’s more standard and much faster.
Thanks, that works! I knew I’d probably have to end up writing a custom function. I’m never opposed to that… I was just wondering if there was another function out there.