Harsh Harsh - 6 months ago 9
PHP Question

How would I call a function in another file?

For example, I have a file error-status.php, which includes a function:

function validateHostName($hostName)
{
if ((strpbrk($hostName,'`~!@#$^&*()=+.[ ]{}\\|;:\'",<>/?')==FALSE) && !ctype_digit($hostName) && eregi("^([a-z0-9-]+)$",$hostName) && ereg("^[^-]",$hostName) && ereg("[^-]$",$hostName))
{
return true;
}
else
{
return false;
}
}


...

How do I call that function from a different PHP file after invoking
require_once
?

require_once('error-status.php');

Answer

Include the file before you call the function.

include 'error-status.php';
validateHostName('myhostname');