9

Is it possible to launch a PHP script, client side, using an HTML web page?

If not, is there a way to embed the PHP into the HTML so it can run client side?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
user2127874
  • 109
  • 1
  • 1
  • 4
  • 1
    Why do you need to do this? – Blender Mar 08 '13 at 03:45
  • There is most likely a way to do the thing that you actually want to do though, you should ask about that instead. – ultranaut Mar 08 '13 at 03:46
  • 2
    @ultranaut I disagree - I think it might be possible. Are you sure it isn't (theoretically) possible to write a PHP interpreter in JavaScript, and then use it to run PHP scripts on the client side? – Anderson Green Mar 13 '13 at 03:33
  • maybe this would help: http://phpjs.org/ or this one: https://code.google.com/p/php-to-js/ .. since GWT i would like to see a php to javascript compiler too. You just code in one language, web programming is a pain with all the different syntax ... ;-) – KIC Jul 18 '13 at 13:34
  • 3
    [Disclaimer: I am the author] You could use Uniter to execute PHP client side - it is essentially a PHP interpreter written in JavaScript - http://asmblah.github.io/uniter/demo/interactive.html - Sorry, I would have added this as an answer if the question wasn't closed. – Dan Phillimore Jan 22 '14 at 15:13
  • A long long long time ago, in the beginning of the php4 era, there was a Mozilla (pre-firefox, if memory serves) plugin for doing client side php code. It even supported – Yitzhak Feb 16 '18 at 16:07

2 Answers2

8

I think what you want is JavaScript. PHP is meant for server-side and JavaScript is meant for client side, among other things.

B001ᛦ
  • 2,036
  • 6
  • 23
  • 31
blaedj
  • 322
  • 2
  • 9
  • Is it possible to do the same thing with javascript as it is with php? – user2127874 Mar 08 '13 at 03:56
  • Yes, like Daniil said. you can think of javascript like php for the client. (this is a very simplistic view, as Daniil pointed out there are many, many applications for javascript). try [Eloquent Javascript](http://eloquentjavascript.net/) for an introduction. – blaedj Mar 08 '13 at 04:02
  • 1
    As of 2020, it's also possible to [compile PHP to WebAssembly](https://github.com/oraoto/pib) and run it in a browser. – Anderson Green Sep 09 '20 at 19:53
3

No. PHP cannot be run in browser. Learn JavaScript, alternatively CoffeScript if you don't like JavaScript's syntax.

Newbyte
  • 2,421
  • 5
  • 22
  • 45
Daniil Ryzhkov
  • 7,416
  • 2
  • 41
  • 58
  • Writing desktop applications. PHP is probably not the very best language to create a desktop application with a graphical user interface, but if you know PHP very well, and would like to use some advanced PHP features in your client-side applications you can also use PHP-GTK to write such programs. You also have the ability to write cross-platform applications this way. PHP-GTK is an extension to PHP, not available in the main distribution. If you are interested in [PHP-GTK](http://gtk.php.net/), visit » its own website. – amalBit Sep 13 '13 at 12:24
  • Have they been updating PHP-GTK? Last I looked, it was kind of a mess. – Yitzhak Feb 16 '18 at 16:10
  • 1
    To run a PHP script in a browser, you would need to [compile it into JavaScript](https://stackoverflow.com/questions/1995362/looking-for-transpiler-php-to-javascript) first. – Anderson Green Mar 13 '18 at 20:33
  • https://atymic.dev/blog/client-side-php – Dan Froberg Jul 20 '22 at 18:37