I don't know how capable PHP today in doing that, but base on my understanding on what you want to do is you want to execute a serverside PHP method within javascript which I think possible only by posting your code back to the server. That means you need to post all content to the server or doing the AJAX way which I think best suit for these....
Sa tinud-anay lang pud wla nako alamag ani PHP kay nakasulay ko 2001 paman guro to.. hehehe.. unya basic pajud.. hahaha...
Love endures even death...pokloy