Is there some way to have a function which can be called from both a JavaScript script and from PHP (for example when validating form data)? One way I can think of is having a PHP function, and making an AJAX request, to a PHP document which will call the function and send back the result. But is there some other simpler way?