You are mixing two different execution paradigms here:
PHP is executed server-side. That means that the server, hosting your code executes it. As a consequence PHP code is usually not visible to clients. The execution of the php code is triggered by a clients request, and the output of the script (e.g. produced by the printf-function) is passed to the client.
Javascript however, is executed client-side. This implies that the cpu of the website visitor is actually used to execute the code. The code is 100% visible to the client. So what you paste within an HTML documents script-tags is executed client side. It is seen by the client. Contrary, PHP code is not meant to be directly pasted within script tags.
These are very generalized statements, that do always hold. However, they should give you a rough sketch. There is a quite nice answer in this thread that should help you for a better distinction. You should certainly learn these basics, before continuing.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…