PHP Sandbox, test PHP online, PHP tester
https://sandbox.onlinephpfunctions.com/
<?php
// 單行註解
/*
多行註解
*/
echo "Hello World\n";
ECHO "heLLo World\n";
eChO "Hello wORlD\n";
?>
<filename>.php
<?php
$a = 123;
$_a = -123;
$b = 0123;
$_b = -0123;
$c = 0x123;
$_c = -0x123;
$f = 123.45;
$_f = -123.45;
?>
<?php
$t = true;
$f = false;
$str = "NISRA!!!";
echo "I love $str!\n";
echo 'I love $str!\n';
echo "123" . '4' . ".5\n";
echo "123" + 4 + 0.56;
?>
<?php
$t = date("H");
if("6" <= $t && $t < "12"){
echo "Good morning!";
}
elseif("12" <= $t && $t < "18"){
echo "Good afternoon!";
}
else{
echo "Good night!";
}
?>
<?php
$i = 1;
while($i <= 5){
echo $i++;
}
$j = 1;
do{
echo $j++;
}while($j <= 5);
for($k = 1; $k <= 5; $k++){
if($k == 5){
break;
}
elseif($k == 3){
continue;
}
echo $k;
}
$num = array(1, 2, 3, 4, 5);
foreach($num as $n){
echo "$n";
}
?>
<?php
for($i = 0; $i < 9; $i++){
for($j = 0; $j < 9; $j++){
if($i + $j == 4 || $i - $j == 4 || $i + $j == 12 || $j - $i == 4){
echo "*";
}
else{
echo " ";
}
}
echo "\n";
}
?>
<?php
$f = array("A", "B");
echo $f[0] . " is " . $f[1] . "'s friend\n";
$f[2] = "C";
echo $f[1] . " is " . $f[2] . "'s friend\n";
$age = array("LAVI" => "19");
echo "LAVI is " . $age['LAVI'] . " years old.\n";
$data = array(array("LAVI", 160, 449),
array("TsaiTing", 165, 217),
);
?>
<?php
function NISRA($arg){
if($arg === "name"){
echo "Network and Information Security Research Association\n";
}
elseif($arg === "year"){
return "since 2007\n";
}
}
nisra("name");
echo nisra(123);
function sum(int $x = 1, int $y = 2) {
return $x + $y;
}
echo sum(2, 3);
echo sum(4);
echo sum();
function add(&$value) {
$value++;
}
$num = 1;
add($num);
echo $num;
?>
<?php
function Pascal_Traingle($layer){
$pt = array(0);
for($i = 1; $i <= $layer; $i++){
$pt[$i] = 1;
}
for($i = 1; $i <= $layer; $i++){
for($j = 0; $j < $layer - $i; $j++){
echo " ";
}
for($j = $i; $j > 0; $j--){
echo $pt[$j] . " ";
$pt[$j] += $pt[$j - 1];
}
echo "\n";
}
}
Pascal_Traingle(5);
?>
<?php
var_dump(0 == "nisra");
var_dump(1 == "01");
var_dump("1" == "01");
?>
<?php
$x = 75;
$y = 25;
function addition() {
$GLOBALS['z'] = $GLOBALS['x'] + $GLOBALS['y'];
}
addition();
echo $z;
?>
<?php
echo $_SERVER['PHP_SELF'];
echo $_SERVER['SERVER_NAME'];
echo $_SERVER['SCRIPT_NAME'];
?>
<?php
$name = $_GET['user'];
echo 'Hello, ' . $name;
?>
<?php
$n = $_GET['side'];
$h = $n * 2 - 1;
$d = $n - 1;
for($i = 0; $i < $h; $i++){
for($j = 0; $j < $h; $j++){
if($i + $j == $d || $i - $j == $d || $i + $j == $d * 3 || $j - $i == $d){
echo "*";
}
else{
echo " ";
}
}
echo "\n";
}
?>
<?php
$p = $_GET['path'];
echo file_get_contents($p);
?>
<?php
// http://localhost/?path=file:///etc/passwd
$p = $_GET['path'];
echo file_get_contents($p);
?>
<?php
// ?file=php://filter/read=convert.base64-encode/resource=index.php
echo 'Hello World!';
?>