PHP is a server-side language, so there is no way for it to directly interact with the client.
The only way to trigger any code when the user clicks a link is to either have that link redirect the user to a specific PHP page, which then runs the code, or have a client-side language (like Javascript) detect the click and trigger whatever code you need triggered.
If you need anything more specific than that, then you are going to have to be more specific in your question. We don't like to guess.
Comment