Remove irrelevant and duplicate guides from the php guide (#19540)

This commit is contained in:
Stephan Grobler
2018-10-27 18:21:21 +02:00
committed by Kristofer Koishigawa
parent 1c4e4b13ea
commit c90ec7819d
6 changed files with 67 additions and 319 deletions

View File

@ -1,108 +0,0 @@
---
title: AJAX
---
## AJAX
<!-- Please add any articles you think might be helpful to read before writing the article -->
<b>AJAX</b> stands for <b>Asynchronous JavaScript And XML</b>. It is not a programming language. It is a technology for developing better, faster and interactive Web Applications using HTML, CSS, JavaScript and XML.
<ol>
<li>HTML : Hypertext Markup Language (HTML) is used for defining the structure of a Web Application.</li>
<li>CSS : Cascading Style Sheet (CSS) is used to provide look and style to a Web Application.</li>
<li>JavaScript : JavaScript is used for making a Web Application interactive, interesting and user friendly.</li>
<li>XML : Extensible Markup Language (XML) is a format to store and transport data from the Web Server.</li>
</ol>
<h4>What's the meaning of Asynchronous in AJAX?</h4>
<p>Asynchronous means that the the Web Application could send and receive data from the Web Server without refreshing the page. This background process of sending and receiving data from the server along with updating different sections of a web page defines Asynchronous property/feature of AJAX.<p>
<h4>How <b>AJAX</b> works?</h4>
<p>AJAX makes use of a browser built-in <b>XMLHttpRequest object</b> to request data from a Web Server and <b>HTML DOM</b> to display or use the data.</p>
<p><b>XMLHttpRequest Object</b> : It is an API in the form an object whose methods help in transfer of data between a web browser and a web server.</p>
<p><b>HTML DOM</b> : When a web page is loaded, the browser creates a Document Object Model of the page.</p>
<img src="https://i.imgur.com/pfC7QFH.png" title="How AJAX work" />
<b>Create a XMLHttpRequest Object :</b>
```javascript
var xhttp = new XMLHttpRequest();
```
<b>Properties of XMLHttpRequest object :</b>
```readystate``` is a property of the XMLHttpRequest Object which holds the status of the XMLHttpRequest.
<ul>
<li>0: request not initialized</li>
<li>1: server connection established</li>
<li>2: request received</li>
<li>3: processing request</li>
<li>4: request finished and response is ready</li>
</ul>
```onreadystatechange``` is a property of the XMLHttpRequest Object which defines a function to be called when the readyState property changes.<br/>
```status``` is a property of the XMLHttpRequest Object which returns the status-number of a request
<ul>
<li>200: "OK"</li>
<li>403: "Forbidden"</li>
<li>404: "Not Found"</li>
</ul>
<b>XMLHttpRequest Object Methods :</b>
To send a request to a Web Server, we use the open() and send() methods of the XMLHttpRequest object.
```javascript
xhttp.open("GET", "content.txt", true);
xhttp.send();
```
<b>Create a function changeContent() using JavaScript :</b>
```javascript
function changeContent() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("foo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "content.txt", true);
xhttp.send();
}
```
<b>AJAX example to change content of a web page :</b>
```HTML
<!DOCTYPE html>
<html>
<body>
<div id="foo">
<h2>The XMLHttpRequest Object</h2>
<button type="button" onclick="changeContent()">Change Content</button>
</div>
<script>
function changeContent() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("foo").innerHTML =
this.responseText;
}
};
xhttp.open("GET", "content.txt", true);
xhttp.send();
}
</script>
</body>
</html>
```
The file ```content.txt``` should be present in the root directory of the Web Application.
### Sources
- [W3Schools](https://www.w3schools.com/js/js_ajax_intro.asp)
- [MDN web docs](https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX/Getting_Started)
### Other Resources
- [W3Schools](https://www.w3schools.com/js/js_ajax_intro.asp)
- [MDN web docs](https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX/Getting_Started)

View File

@ -1,69 +0,0 @@
---
title: PHP Switch
---
## PHP Switch
The `switch` statement in PHP is similar to a series of `if ` statements on same expression. The `switch` statement is used to execute different actions at different conditions. The Syntax of the `switch` statement is follows
```
switch (expression) {
case label1:
// code block to be executed if there is a match with result of expression
break;
case label2:
// code block to be executed if there is a match with result of expression
break;
case label3:
// code block to be executed if there is a match with result of expression
break;
default:
       // code block to be executed if there is no match with result of expression
}
```
When we run the program , the expression inside the `switch` statement is evaluated. The result of that expression is checked with corresponding labels if there is a match then corresponding `case` block is executed. If no match is found with any of the case statements, only the block of code following the `default` are executed.
Illustration of `switch` statement with an example
```
<?php
$i = 1
switch ($i) {
case 0:
echo "i equals 0";
break;
case 1:
echo "i equals 1";
break;
case 2:
echo "i equals 2";
break;
}
?>
```
The `switch` statement can also be used without `break` statement. In that case , statements after the matched cases will be executed. Below is an usage of `switch` statement without `break` statement.
```
<?php
switch ($i) {
case 0:
echo "i equals 0";
case 1:
echo "i equals 1";
case 2:
echo "i equals 2";
}
?>
/*output --> i equals 0i equals 1i equals 2 */
```
#### More Information:
[Switch Statement - PHP Documentation](http://php.net/manual/en/control-structures.switch.php)
[PHP5 Switch - W3Schools](https://www.w3schools.com/php/php_switch.asp)

View File

@ -1,92 +0,0 @@
---
title: Switch statement
---
# Switch
`Switch` is a selection statement that will select a switch statement and execute it from the list of candidates. Switch consists of `case` and an optional `default`. The execution can be stopped by using a `break` or `return`.
## Syntax
```
switch(x)
{
case value1:
//execute if x = value1
break;
case value2:
//execute if x = value2
break;
...
default:
execute if x is different with cases above
}
```
## Example
```php
<?php
//initialize with a random integer within range
$diceNumber = mt_rand(1, 6);
//initialize
$numText = "";
//calling switch statement
switch($diceNumber)
{
case 1:
$numText = "One";
break;
case 2:
$numText = "Two";
break;
case 3:
case 4:
// case 3 and 4 will go to this line
$numText = "Three or Four";
break;
case 5:
$numText = "Five";
echo $numText;
// break; //without specify break or return it will continue execute to next case.
case 6:
$numText = "Six";
echo $numText;
break;
default:
$numText = "unknown";
}
//display result
echo 'Dice show number '.$numText.'.';
?>
```
## Output
```
if case is 1
> Dice show number One.
if case is 2
> Dice show number Two.
if case is 3
> Dice show number Three or Four.
if case is 4
> Dice show number Three or Four.
if case is 5
> FiveSixDice show number Six.
if case is 6
> SixDice show number Six.
if none of the above
> Dice show number unknown.
```

View File

@ -1,26 +0,0 @@
---
title: Switch Statements
---
## Switch Statements
Switch statements execute blocks of code based on the value of a condition.
### Syntax:
```PHP
switch(x) {
case 1:
statement1;
break;
case 2:
statement2;
break;
default:
defaultstatement;
}
```
In the above example, x is the condition. The statements following the case that matches will be executed. If there are no matches, the default statement(s) will be run.
The `break` keyword is used to end each case.
### More Information:
<a href='http://php.net/manual/en/control-structures.switch.php' target='_blank' rel='nofollow'>PHP Switch</a>

View File

@ -84,5 +84,72 @@ While break can be omitted without causing fall-through in some instances (see b
}
```
## Example
```php
<?php
//initialize with a random integer within range
$diceNumber = mt_rand(1, 6);
//initialize
$numText = "";
//calling switch statement
switch($diceNumber)
{
case 1:
$numText = "One";
break;
case 2:
$numText = "Two";
break;
case 3:
case 4:
// case 3 and 4 will go to this line
$numText = "Three or Four";
break;
case 5:
$numText = "Five";
echo $numText;
// break; //without specify break or return it will continue execute to next case.
case 6:
$numText = "Six";
echo $numText;
break;
default:
$numText = "unknown";
}
//display result
echo 'Dice show number '.$numText.'.';
?>
```
## Output
```
if case is 1
> Dice show number One.
if case is 2
> Dice show number Two.
if case is 3
> Dice show number Three or Four.
if case is 4
> Dice show number Three or Four.
if case is 5
> FiveSixDice show number Six.
if case is 6
> SixDice show number Six.
if none of the above
> Dice show number unknown.
```
#### More Information:
* [php.net docs Switch](https://secure.php.net/manual/en/control-structures.switch.php")

View File

@ -1,24 +0,0 @@
---
title: Syntax
---
## Syntax
PHP is a language allowing you to include dynamic content in otherwise static webpages. It is written inline with html, simply rename a .html file to .php (web-server must have php installed) to get started.
```PHP
<!DOCTYPE html>
<html>
<head>
<title>PHP Example</title>
</head>
<body>
<h1>PHP Example</h1>
<?php
echo "Hello World from PHP!";
?>
</body>
</html>
```
#### More Information:
* <a href="https://secure.php.net/docs.php">php.net - PHP Documentation</a>