ConalMullan, it has to do with the curly braces in preg_match().
I don’t know exactly what they do in the eval() function (Insert PHP works by putting the code through the eval() function), as I haven’t yet completed my testing.
In the meantime, this should work as a work-around:
[insert_php]
function isDomain($domain1)
{
if (preg_match('/^.+\.[a-z][a-z]+$/', $domain1)) { return true; }
return false;
}
echo isDomain('example.com') ? 'YES' : 'no';
[/insert_php]
Will
Sorry, inadvertently ticked the “resolved” box and see no way to un-resolve the thread.
Thanks Will – that has worked!
I have one more that is doing the same thing but apparently for a different reason?
function isIP($ip1) {return(preg_match('/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.'.'(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.'.'(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.'.'(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/',$ip1));}
I looks like you’re finding most of them. I apologize.
Yes, the vertical bar character creates havoc in the eval() function. I’ve never found a work-around for that. It and other elements that don’t work in Insert PHP are talked about here:
http://www.willmaster.com/software/WPplugins/insert-php-wordpress-plugin-instructions.php#nonworkingelements
(The curly braces within a regex aren’t listed there, yet. Haven’t finished testing.)
Perhaps this can be used to validate the characters of an IP address:
function ValidateIPaddressFormat($ip)
{
$arr = explode('.',$ip);
if( count($arr) != 4 ) { return false; }
foreach( $arr as $chunk )
{
if( preg_match('/\D/',$chunk) ) { return false; }
if( $chunk > 255 ) { return false; }
}
return true;
}
Will
Thanks Will – all good now.
I really appreciate your help with those. I was getting a bit stuck!
Conal.