3

Trying to learn PHP and a more experienced dev made a number of modifications to my PHP script but I did not get an opp to ask what does the "#!" next to the path in my PHP script? This sits at the very top of the PHP file that I was working on:

#!/opt/local/bin/php

Any help/direction would be greatly appreciated.

Regards.

Melinda
  • 1,501
  • 5
  • 25
  • 58
  • [Why exclamation is used in URLs? [closed]][1] [1]: http://stackoverflow.com/questions/4376719/why-exclamation-is-used-in-urls – Ben Sep 20 '12 at 11:33
  • That is not PHP, it's a shell command for linux systems. I'm guessing that is for CLI. – Daniel Sep 20 '12 at 11:33

3 Answers3

4

This is a way to tell Linux to run the script code using the application at /opt/local/bin/php. If you were running PHP as a plugin to apache, you'd use the <?php ?> tags to identify PHP code.

Leonard
  • 3,012
  • 2
  • 31
  • 52
  • 2
    The `` tags to identify PHP code are required by a "standalone" interpreter as well. Anything not enclosed by them is directed to STDOUT. – lafor Sep 20 '12 at 11:51
3

Wikipedia explains it fairly simple: Shebang (unix)

Under Unix-like operating systems, when a script with a shebang is run as a program, the program loader parses the rest of the script's initial line as an interpreter directive; the specified interpreter program is run instead, passing to it as an argument the path that was initially used when attempting to run the script.[11] For example, if a script is named with the path "path/to/script", and it starts with the following line:

#!/bin/sh

then the program loader is instructed to run the program "/bin/sh" instead (usually this is the Bourne shell or a compatible shell), passing "path/to/script" as the first argument. The shebang line is usually ignored by the interpreter because the "#" character is a comment marker in many scripting languages; some language interpreters that do not use the hash mark to begin comments (such as Scheme) still may ignore the shebang line in recognition of its purpose.[12]

Janis Veinbergs
  • 6,907
  • 5
  • 48
  • 78
2

It's called a Shebang see Wikipedia

Under Unix-like operating systems, when a script with a shebang is run as a program, the program loader parses the rest of the script's initial line as an interpreter directive; the specified interpreter program is run instead, passing to it as an argument the path that was initially used when attempting to run the script.[11]

huysentruitw
  • 27,376
  • 9
  • 90
  • 133