PHP: Difference between revisions

No edit summary
Marked this version for translation
Line 1: Line 1:
<languages /><translate>'''PHP''' stands for '''Ph'''antastic '''P'''rogramming. You can use it to make things happen on pages.
<languages /><translate><!--T:1-->
'''PHP''' stands for '''Ph'''antastic '''P'''rogramming. You can use it to make things happen on pages.


<!--T:2-->
It's different from JavaScript because JavaScript runs in your browser and PHP runs somewhere else I don't know where.They won't tell me where it runs.
It's different from JavaScript because JavaScript runs in your browser and PHP runs somewhere else I don't know where.They won't tell me where it runs.


<!--T:3-->
== Having a PHP ==
== Having a PHP ==
You can make a php script by calling it <code>something.php</code>. It's a good idea to actually call it <code>something/index.php</code> so the URL remains the same if you decide to stop using PHP (a wise choice).
You can make a php script by calling it <code>something.php</code>. It's a good idea to actually call it <code>something/index.php</code> so the URL remains the same if you decide to stop using PHP (a wise choice).


<!--T:4-->
== Writing a PHP ==
== Writing a PHP ==
You can write a PHP script like this:
You can write a PHP script like this:
Line 12: Line 16:
There's a pretty okay guide on the [https://www.php.net/manual/en/langref.php PHP website].
There's a pretty okay guide on the [https://www.php.net/manual/en/langref.php PHP website].


<!--T:5-->
The <code><?php</code> bit tells PHP you're about to write some PHP. You can stop writing PHP and start writing HTML with <code>?></code>.  
The <code><?php</code> bit tells PHP you're about to write some PHP. You can stop writing PHP and start writing HTML with <code>?></code>.  


<!--T:6-->
Sometimes you'll want to insert some values from PHPland into your HTML, which you can do like this:
Sometimes you'll want to insert some values from PHPland into your HTML, which you can do like this:
  <?php
  <?php
Line 23: Line 29:
  <nowiki></p></nowiki>
  <nowiki></p></nowiki>


<!--T:7-->
Note that if you're rendering user input in this way, you should wrap it in the <code>[https://www.php.net/manual/en/function.htmlspecialchars.php htmlspecialchars]</code> function, lest you become vulnerable to an [[wikipedia:Cross-site_scripting|XSS (Cross-site scripting)]] attack in which a nasty fellow inputs [[:Category:Evil Pages|evil]] HTML to make your site go [[:Category:Bad pages|bad]] and rotten like a hard-boiled egg.
Note that if you're rendering user input in this way, you should wrap it in the <code>[https://www.php.net/manual/en/function.htmlspecialchars.php htmlspecialchars]</code> function, lest you become vulnerable to an [[wikipedia:Cross-site_scripting|XSS (Cross-site scripting)]] attack in which a nasty fellow inputs [[:Category:Evil Pages|evil]] HTML to make your site go [[:Category:Bad pages|bad]] and rotten like a hard-boiled egg.
[[Category:Pages with some amount of information in them]]</translate>
[[Category:Pages with some amount of information in them]]</translate>