This commit is contained in:
RobinNixon
2021-04-18 15:31:38 +01:00
parent f63a81074d
commit 188af22a54
224 changed files with 79 additions and 2241 deletions
+1 -2
View File
@@ -1,10 +1,9 @@
<?php
class User
{
{
function __construct($param1, $param2)
{
// Constructor statements go here
public $username = "Guest";
}
}
?>
+1 -1
View File
@@ -3,7 +3,7 @@
$text = fgets($fh);
fseek($fh, 0, SEEK_END);
fwrite($fh, "$text") or die("Could not write to file");
fwrite($fh, "\n$text") or die("Could not write to file");
fclose($fh);
echo "File 'testfile.txt' successfully updated";
+1 -1
View File
@@ -1,5 +1,5 @@
<?php // exec.php
$cmd = "dir"; // Windows
$cmd = "dir"; // Windows, Mac, Linux
// $cmd = "ls"; // Linux, Unix & Mac
exec(escapeshellcmd($cmd), $output, $status);
View File
View File
View File
View File
View File
View File
+1 -1
View File
@@ -1,4 +1,4 @@
<?php // query-pdo.php
<?php // query.php
require_once 'login.php';
try
+24
View File
@@ -0,0 +1,24 @@
<?php //fetchrow.php
require_once 'login.php';
try
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (PDOException $e)
{
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$query = "SELECT * FROM classics";
$result = $pdo->query($query);
while ($row = $result->fetch(PDO::FETCH_BOTH)) // Style of fetch
{
echo 'Author: ' . htmlspecialchars($row['author']) . "<br>";
echo 'Title: ' . htmlspecialchars($row['title']) . "<br>";
echo 'Category: ' . htmlspecialchars($row['categoryr']) . "<br>";
echo 'Year: ' . htmlspecialchars($row['year']) . "<br>";
echo 'ISBN: ' . htmlspecialchars($row['isbn']) . "<br><br>";
}
?>
+2 -2
View File
@@ -1,6 +1,6 @@
<?php // login.php
$host = 'localhost';
$data = 'publications';
$host = 'localhost'; // Change as necessary
$data = 'publications'; // Change as necessary
$user = 'root'; // Change as necessary
$pass = 'mysql'; // Change as necessary
$chrs = 'utf8mb4';
+24
View File
@@ -0,0 +1,24 @@
<?php // query.php
require_once 'login.php';
try
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (PDOException $e)
{
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$query = "SELECT * FROM classics";
$result = $pdo->query($query);
while ($row = $result->fetch())
{
echo 'Author: ' . htmlspecialchars($row['author']) . "<br>";
echo 'Title: ' . htmlspecialchars($row['title']) . "<br>";
echo 'Category: ' . htmlspecialchars($row['categoryr']) . "<br>";
echo 'Year: ' . htmlspecialchars($row['year']) . "<br>";
echo 'ISBN: ' . htmlspecialchars($row['isbn']) . "<br><br>";
}
?>
+1 -1
View File
@@ -9,7 +9,7 @@
</head>
<body>
Your name is: $name<br>
<form method="post" action="formtest.php">
<form method="post" action="formtest2.php">
What is your name?
<input type="text" name="name">
<input type="submit">
+3 -4
View File
@@ -1,7 +1,6 @@
<form method="post" action="calc.php"><pre>
Loan Amount <input type="text" name="principle">
Monthly Repayment <input type="text" name="monthly">
Number of Years <input type="text" name="years" value="25">
Interest Rate <input type="text" name="rate" value="6">
Loan Amount <input type="text" name="principal">
Number of Years <input type="text" name="years" value="15">
Interest Rate <input type="text" name="interest" value="3">
<input type="submit">
</pre></form>
+13
View File
@@ -0,0 +1,13 @@
<html>
<head>
<title>Hello World</title>
</head>
<body>
<script type="text/javascript">
document.write("Hello World")
</script>
<noscript>
Your browser doesn't support or has disabled JavaScript
</noscript>
</body>
</html>
-4
View File
@@ -1,4 +0,0 @@
<?php
echo "Hello world";
?>
-6
View File
@@ -1,6 +0,0 @@
<?php
/* This is a section
of multi-line comments
which will not be
interpreted */
?>
-5
View File
@@ -1,5 +0,0 @@
<?php
$mycounter = 1;
$mystring = "Hello";
$myarray = array("One", "Two", "Three");
?>
-7
View File
@@ -1,7 +0,0 @@
<?php // test1.php
$username = "Fred Smith";
echo $username;
echo "<br>";
$current_user = $username;
echo $current_user;
?>
-7
View File
@@ -1,7 +0,0 @@
<?php
$oxo = array(array('x', ' ', 'o'),
array('o', 'o', 'x'),
array('x', 'o', ' '));
echo $oxo[1][2];
?>
-8
View File
@@ -1,8 +0,0 @@
<?php
$author = "Steve Ballmer";
echo "Developers, Developers, developers, developers, developers,
developers, developers, developers, developers!
- $author.";
?>
-10
View File
@@ -1,10 +0,0 @@
<?php
$author = "Bill Gates";
$text = "Measuring programming progress by lines of code is like
Measuring aircraft building progress by weight.
- $author.";
echo $text;
?>
-11
View File
@@ -1,11 +0,0 @@
<?php
$author = "Brian W. Kernighan";
echo <<<_END
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it.
- $author.
_END;
?>
-11
View File
@@ -1,11 +0,0 @@
<?php
$author = "Scott Adams";
$out = <<<_END
Normal people believe that if it aint broke, dont fix it.
Engineers believe that if it aint broke, it doesnt have enough
features yet.
- $author.
_END;
?>
-4
View File
@@ -1,4 +0,0 @@
<?php
$number = 12345 * 67890;
echo substr($number, 3, 1);
?>
-5
View File
@@ -1,5 +0,0 @@
<?php
$pi = "3.1415927";
$radius = 5;
echo $pi * ($radius * $radius);
?>
-6
View File
@@ -1,6 +0,0 @@
<?php
function longdate($timestamp)
{
return date("l F jS Y", $timestamp);
}
?>
-7
View File
@@ -1,7 +0,0 @@
<?php
function longdate($timestamp)
{
$temp = date("l F jS Y", $timestamp);
return "The date is $temp";
}
?>
-9
View File
@@ -1,9 +0,0 @@
<?php
$temp = "The date is ";
echo longdate(time());
function longdate($timestamp)
{
return $temp . date("l F jS Y", $timestamp);
}
?>
-9
View File
@@ -1,9 +0,0 @@
<?php
$temp = "The date is ";
echo $temp . longdate(time());
function longdate($timestamp)
{
return date("l F jS Y", $timestamp);
}
?>
-9
View File
@@ -1,9 +0,0 @@
<?php
$temp = "The date is ";
echo longdate($temp, time());
function longdate($text, $timestamp)
{
return $text . date("l F jS Y", $timestamp);
}
?>
-13
View File
@@ -1,13 +0,0 @@
<?php
echo test();
echo "<br><br>";
echo test();
function test()
{
static $count = 0;
echo $count;
$count++;
}
?>
-5
View File
@@ -1,5 +0,0 @@
<?php
static $int = 0; // Allowed
static $int = 1+2; // Disallowed (will produce a Parse error)
static $int = sqrt(144); // Disallowed
?>
-6
View File
@@ -1,6 +0,0 @@
<?php
echo "a: [" . (20 > 9) . "]<br>";
echo "b: [" . (5 == 6) . "]<br>";
echo "c: [" . (1 == 0) . "]<br>";
echo "d: [" . (1 == 1) . "]<br>";
?>
-4
View File
@@ -1,4 +0,0 @@
<?php // test2.php
echo "a: [" . TRUE . "]<br>";
echo "b: [" . FALSE . "]<br>";
?>
-10
View File
@@ -1,10 +0,0 @@
<?php
$myname = "Brian";
$myage = 37;
echo "a: " . 73 . "<br>"; // Numeric literal
echo "b: " . "Hello" . "<br>"; // String literal
echo "c: " . FALSE . "<br>"; // Constant literal
echo "d: " . $myname . "<br>"; // String variable
echo "e: " . $myage . "<br>"; // Numeric variable
?>
-9
View File
@@ -1,9 +0,0 @@
<?php
$day_number = 340; // Assignment by Value
$days_to_new_year = 366 - $day_number; // Assignment by Expression
if ($days_to_new_year < 30) // Condition
{
echo "Not long now till new year"; // Statement
}
?>
-3
View File
@@ -1,3 +0,0 @@
<?php
$level = $score = $time = 0;
?>
-5
View File
@@ -1,5 +0,0 @@
<?php
$month = "March";
if ($month == "March") echo "It's springtime";
?>
-7
View File
@@ -1,7 +0,0 @@
<?php
$a = "1000";
$b = "+1000";
if ($a == $b) echo "1";
if ($a === $b) echo "2";
?>
-7
View File
@@ -1,7 +0,0 @@
<?php
$a = "1000";
$b = "+1000";
if ($a != $b) echo "1";
if ($a !== $b) echo "2";
?>
-7
View File
@@ -1,7 +0,0 @@
<?php
$a = 2; $b = 3;
if ($a > $b) echo "$a is greater than $b<br>";
if ($a < $b) echo "$a is less than $b<br>";
if ($a >= $b) echo "$a is greater than or equal to $b<br>";
if ($a <= $b) echo "$a is less than or equal to $b<br>";
?>
-8
View File
@@ -1,8 +0,0 @@
<?php
$a = 1; $b = 0;
echo ($a AND $b) . "<br>";
echo ($a or $b) . "<br>";
echo ($a XOR $b) . "<br>";
echo !$a . "<br>";
?>
-3
View File
@@ -1,3 +0,0 @@
<?php
if ($finished == 1 or getnext() == 1) exit;
?>
-5
View File
@@ -1,5 +0,0 @@
<?php
$gn = getnext();
if ($finished == 1 or $gn == 1) exit;
?>
-7
View File
@@ -1,7 +0,0 @@
<?php
if ($bank_balance < 100)
{
$money = 1000;
$bank_balance += $money;
}
?>
-12
View File
@@ -1,12 +0,0 @@
<?php
if ($bank_balance < 100)
{
$money = 1000;
$bank_balance += $money;
}
else
{
$savings += 50;
$bank_balance -= 50;
}
?>
-17
View File
@@ -1,17 +0,0 @@
<?php
if ($bank_balance < 100)
{
$money = 1000;
$bank_balance += $money;
}
elseif ($bank_balance > 200)
{
$savings += 100;
$bank_balance -= 100;
}
else
{
$savings += 50;
$bank_balance -= 50;
}
?>
-10
View File
@@ -1,10 +0,0 @@
<?php
$page = "test";
if ($page == "Home") echo "You selected Home";
elseif ($page == "About") echo "You selected About";
elseif ($page == "News") echo "You selected News";
elseif ($page == "Login") echo "You selected Login";
elseif ($page == "Links") echo "You selected Links";
else echo "Unrecognized selection";
?>
-15
View File
@@ -1,15 +0,0 @@
<?php
switch ($page)
{
case "Home": echo "You selected Home";
break;
case "About": echo "You selected About";
break;
case "News": echo "You selected News";
break;
case "Login": echo "You selected Login";
break;
case "Links": echo "You selected Links";
break;
}
?>
-23
View File
@@ -1,23 +0,0 @@
<?php
switch ($page)
{
case "Home":
echo "You selected Home";
break;
case "About":
echo "You selected About";
break;
case "News":
echo "You selected News";
break;
case "Login":
echo "You selected Login";
break;
case "Links":
echo "You selected Links";
break;
default:
echo "Unrecognized selection";
break;
}
?>
-13
View File
@@ -1,13 +0,0 @@
<?php
switch ($page):
case "Home":
echo "You selected Home";
break;
// etc...
case "Links":
echo "You selected Links";
break;
endswitch;
?>
-3
View File
@@ -1,3 +0,0 @@
<?php
echo $fuel <= 1 ? "Fill tank now" : "There's enough fuel";
?>
-3
View File
@@ -1,3 +0,0 @@
<?php
$enough = $fuel <= 1 ? FALSE : TRUE;
?>
-9
View File
@@ -1,9 +0,0 @@
<?php
$fuel = 10;
while ($fuel > 1)
{
// Keep driving …
echo "There's enough fuel";
}
?>
-9
View File
@@ -1,9 +0,0 @@
<?php
$count = 1;
while ($count <= 12)
{
echo "$count times 12 is " . $count * 12 . "<br>";
++$count;
}
?>
-6
View File
@@ -1,6 +0,0 @@
<?php
$count = 0;
while (++$count <= 12)
echo "$count times 12 is " . $count * 12 . "<br>";
?>
-7
View File
@@ -1,7 +0,0 @@
<?php
$count = 1;
do
echo "$count times 12 is " . $count * 12 . "<br>";
while (++$count <= 12);
?>
-8
View File
@@ -1,8 +0,0 @@
<?php
$count = 1;
do {
echo "$count times 12 is " . $count * 12;
echo "<br>";
} while (++$count <= 12);
?>
-4
View File
@@ -1,4 +0,0 @@
<?php
for ($count = 1 ; $count <= 12 ; ++$count)
echo "$count times 12 is " . $count * 12 . "<br>";
?>
-7
View File
@@ -1,7 +0,0 @@
<?php
for ($count = 1 ; $count <= 12 ; ++$count)
{
echo "$count times 12 is " . $count * 12;
echo "<br>";
}
?>
-12
View File
@@ -1,12 +0,0 @@
<?php
$fp = fopen("text.txt", 'wb');
for ($j = 0 ; $j < 100 ; ++$j)
{
$written = fwrite($fp, "data");
if ($written == FALSE) break;
}
fclose($fp);
?>
-12
View File
@@ -1,12 +0,0 @@
<?php
$j = 10;
while ($j > -10)
{
$j--;
if ($j == 0) continue;
echo (10 / $j) . "<br>";
}
?>
-7
View File
@@ -1,7 +0,0 @@
<?php
$a = 56;
$b = 12;
$c = $a / $b;
echo $c;
?>
-5
View File
@@ -1,5 +0,0 @@
<?php
echo strrev(" .dlrow olleH"); // Reverse string
echo str_repeat("Hip ", 2); // Repeat string
echo strtoupper("hooray!"); // String to upper case
?>
-12
View File
@@ -1,12 +0,0 @@
<?php
echo fix_names("WILLIAM", "henry", "gatES");
function fix_names($n1, $n2, $n3)
{
$n1 = ucfirst(strtolower($n1));
$n2 = ucfirst(strtolower($n2));
$n3 = ucfirst(strtolower($n3));
return $n1 . " " . $n2 . " " . $n3;
}
?>
-13
View File
@@ -1,13 +0,0 @@
<?php
$names = fix_names("WILLIAM", "henry", "gatES");
echo $names[0] . " " . $names[1] . " " . $names[2];
function fix_names($n1, $n2, $n3)
{
$n1 = ucfirst(strtolower($n1));
$n2 = ucfirst(strtolower($n2));
$n3 = ucfirst(strtolower($n3));
return array($n1, $n2, $n3);
}
?>
-16
View File
@@ -1,16 +0,0 @@
<?php
$a1 = "WILLIAM";
$a2 = "henry";
$a3 = "gatES";
echo $a1 . " " . $a2 . " " . $a3 . "<br>";
fix_names($a1, $a2, $a3);
echo $a1 . " " . $a2 . " " . $a3;
function fix_names(&$n1, &$n2, &$n3)
{
$n1 = ucfirst(strtolower($n1));
$n2 = ucfirst(strtolower($n2));
$n3 = ucfirst(strtolower($n3));
}
?>
-16
View File
@@ -1,16 +0,0 @@
<?php
$a1 = "WILLIAM";
$a2 = "henry";
$a3 = "gatES";
echo $a1 . " " . $a2 . " " . $a3 . "<br>";
fix_names();
echo $a1 . " " . $a2 . " " . $a3;
function fix_names()
{
global $a1; $a1 = ucfirst(strtolower($a1));
global $a2; $a2 = ucfirst(strtolower($a2));
global $a3; $a3 = ucfirst(strtolower($a3));
}
?>
-6
View File
@@ -1,6 +0,0 @@
<?php
include("library.php");
// Your code goes here
?>
-7
View File
@@ -1,7 +0,0 @@
<?php
include_once("library.php");
// Your code goes here
?>
-5
View File
@@ -1,5 +0,0 @@
<?php
require_once("library.php");
// Your code goes here
?>
-10
View File
@@ -1,10 +0,0 @@
<?php
if (function_exists("array_combine"))
{
echo "Function exists";
}
else
{
echo "Function does not exist - better write our own";
}
?>
-14
View File
@@ -1,14 +0,0 @@
<?php
$object = new User;
print_r($object);
class User
{
public $name, $password;
function save_user()
{
echo "Save User code goes here";
}
}
?>
-20
View File
@@ -1,20 +0,0 @@
<?php
$object = new User;
print_r($object); echo "<br>";
$object->name = "Joe";
$object->password = "mypass";
print_r($object); echo "<br>";
$object->save_user();
class User
{
public $name, $password;
function save_user()
{
echo "Save User code goes here";
}
}
?>
-14
View File
@@ -1,14 +0,0 @@
<?php
$object1 = new User();
$object1->name = "Alice";
$object2 = $object1;
$object2->name = "Amy";
echo "object1 name = " . $object1->name . "<br>";
echo "object2 name = " . $object2->name;
class User
{
public $name;
}
?>
-14
View File
@@ -1,14 +0,0 @@
<?php
$object1 = new User();
$object1->name = "Alice";
$object2 = clone $object1;
$object2->name = "Amy";
echo "object1 name = " . $object1->name . "<br>";
echo "object2 name = " . $object2->name;
class User
{
public $name;
}
?>
-9
View File
@@ -1,9 +0,0 @@
<?php
class User
{
function __construct($param1, $param2)
{
// Constructor statements go here
}
}
?>
-9
View File
@@ -1,9 +0,0 @@
<?php
class Test
{
public $name = "Paul Smith"; // Valid
public $age = 42; // Valid
public $time = time(); // Invalid - calls a function
public $score = $level * 2; // Invalid - uses an expression
}
?>
-10
View File
@@ -1,10 +0,0 @@
<?php
class User
{
public $name, $password;
function get_password()
{
return $this->password;
}
?>
-8
View File
@@ -1,8 +0,0 @@
<?php
$object1 = new User();
$object1->name = "Alice";
echo $object1->name;
class User {}
?>
-9
View File
@@ -1,9 +0,0 @@
<?php
class Test
{
public $name = "Paul Smith"; // Valid
public $age = 42; // Valid
public $time = time(); // Invalid - calls a function
public $score = $level * 2; // Invalid - uses an expression
}
?>
-17
View File
@@ -1,17 +0,0 @@
<?php
Translate::lookup();
class Translate
{
const ENGLISH = 0;
const SPANISH = 1;
const FRENCH = 2;
const GERMAN = 3;
// ...
static function lookup()
{
echo self::SPANISH;
}
}
?>

Some files were not shown because too many files have changed in this diff Show More