Note that this utilises class objects in PHP, and does NOT interact with a DB or other data files in any way!
Sandy's full name: Sandy Bottom
Sandy's hair colour: Sandy Blonde
Sandy's age: 25
Ducky's full name: Ducky Waddles
Ducky's hair colour: Mottled Brown
Ducky's age: 3
---###---
SERVER_NAME: twistedlogic.biz
HTTP_HOST: twistedlogic.biz
HTTP_REFERER: NIL
HTTP_USER_AGENT: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
PHP_SELF: /index.php
SCRIPT_NAME: /index.php
---###---
String $txt1 = 'What happens if an echo appears in a string?' (Note outer single quotes)
String $txt2 = "What happens if an echo appears in a string?" (Note outer double quotes)
String $txt3 = "What happens if an 'echo' appears in a string?" (Note interpolated if showing capitalised)
String $txt4 = "What happens if an \'echo\' appears in a string?" (Note interpolated if showing capitalised)
Txt1 (literal) for consideration, is "$txt1". (not interpolated here)
Txt1 (interpolated) for consideration, is "What happens if an echo appears in a string?"
Txt2 (literal) for consideration, is "$txt2".
Txt2 (interpolated) for consideration, is "What happens if an echo appears in a string?"
Txt3a (literal) for consideration, is "$txt3."
Txt3b (interpolated) for consideration, is "What happens if an 'echo' appears in a string?"
Txt4 (interpolated) for consideration, is "What happens if an \'echo\' appears in a string?"
Txt5a (interpolated) for consideration, is "What happens if an echo appears in a string?"
Txt5b (interpolated) for consideration, is "What happens if an echo appears in a string?"
Txt5c (interpolated) for consideration, is "What happens if an echo appears in a string?"
Txt6 (interpolated) for consideration, is "What happens if an Echo appears in a string?"
Txt7 (interpolated) for consideration, is "What happens if an ECHO appears in a string?"
Txt8a (literal) for consideration, is "What happens if an $echo appears in a string?"
Txt8b (interpolated) for consideration, is "What happens if an ECHO appears in a string?"
String $juice = 'plum.'
I drank some juice made of $juices. (Note the additional "s" on $juice).
I drank some juice made of plums. (Interpolate breakout Variable).
I drank some juice made of {$juice}s. (Note the wrapping curly brackets on {$juice}).
I drank some juice made of plums. (Interpolates {variable} in curly braces).
Using a Variable or Constant before it's declared, FAILS:
Written by undefined
Written by Niloc Nedsmar
Written by Niloc Nedsmar - PHP Learner.
Niloc's age is the same as Ducky's: 3.
Niloc likes plum juice.
|
|
---###---
Cars list (indexed test1): Volvo, BMW and Toyota.
Cars list (indexed test2): Volvo, BMW and Toyota.
Cars list (interpolated test3): 0:Volvo, 1:BMW and 2:Toyota.
Cars1 list (indexed test4): 0:, 1:Volvo and 2:BMW.
Cars1 list (imploded test5): Volvo, BMW, Toyota.
Cars2 list (interpolated test6): 0:, 1:Volvo, 2:BMW and 3:Toyota.
Cars2 list (imploded test7): Volvo, BMW, Toyota.
Cars3 list (interpolated test9): 0:, 1:Volvo, 2:BMW and 3:Toyota.
Cars3 list (imploded test8): Toyota, BMW, Volvo.
Cars list with 4th element (indexed test10): Volvo, BMW, Toyota, Suzuki.
Prior to adding, Variables 'x' = 25, 'y' = 50, 'z' = 100, Variable 'Z' = NULL.
Function 'fAddition()' return value is: 30.
Post adding, Variables 'x' = 25, 'y' = 50, 'z' = 75, Variable 'Z' = 30.
a. $xx = 25.
b. $yy = 50.
50.
c. $xx + $yy = 75.
d. $zz = 55.
Function testing Variables a:1, b:2, c:3.
Function testing literal arguments: 9.
Function testing literal & default: 60.
Function testing defaults: 40.
Function testing Variables a:1, b:2, c:3.
Function testing Variable by Reference a: 84, b:4, c:21.
Function testing prior Variables x:25, y:50, z:1250.
chr(Dec52) = 4.
chr(Oct52) = *.
chr(Hex52) = R.
Compare the following with the original text file
Jargon.txt.
Testing Directory functions:
Number of entities = 28.
Array
(
[0] => .
[1] => ..
[2] => .well-known
[3] => Jargon.txt
[4] => RemoteLink.php
[5] => Template.html
[6] => Test.php
[7] => TestTemplate.php
[8] => ToDoList.html
[9] => TwistedLogic.ico
[10] => UserForm.html
[11] => UserForm.php
[12] => cgi-bin
[13] => class_lib.php
[14] => default.html
[15] => definitions_lib.php
[16] => error_log
[17] => favicon.ico
[18] => frmVehicle.php
[19] => images
[20] => index.php
[21] => movies
[22] => process.php
[23] => robots.txt
[24] => scripts
[25] => sounds
[26] => styles
[27] => todo.php
[28] => topics
[29] => vehicle_lib.php
)
Using the readfile() function on Jargon.txt.
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
1234567890
`~_!@#$%^&*(){}[]<>'";:,.?/|\-+=
SP \s ( ) TAB \t ( ) NL (\n) CR (\r)
WORKING WITH TEXT FILES
Most text files containing text, continue a sentence
across multiple lines, and aren't concerned with
page layout or formatting, beyond sentences and paragraphs.
'Political Jargon'
propaganda
zealot
intelligence
security
[EOF]
File transfer 408bytes.
abcdefghijklm.
Number of characters is 13.
Letter 'f' is in position 6.
Array
(
[0] => ABCDEFGHIJKLMNOPQRSTUVWXYZ
[1] => abcdefghijklmnopqrstuvwxyz
[2] => 1234567890
[3] => `~_!@#$%^&*(){}[]<>'";:,.?/|\-+=
[4] => SP \s ( ) TAB \t ( ) NL (\n) CR (\r)
[5] =>
[6] => WORKING WITH TEXT FILES
[7] => Most text files containing text, continue a sentence
[8] => across multiple lines, and aren't concerned with
[9] => page layout or formatting, beyond sentences and paragraphs.
[10] =>
[11] => 'Political Jargon'
[12] => propaganda
[13] => zealot
[14] => intelligence
[15] => security
[16] => [EOF]
)
.
Jargon.txt contains 17 lines.
Line (+html) 0 ABCDEFGHIJKLMNOPQRSTUVWXYZ
Line (+html) 1 abcdefghijklmnopqrstuvwxyz
Line (+html) 2 1234567890
Line (+html) 3 `~_!@#$%^&*(){}[]<>'";:,.?/|\-+=
Line (+html) 4 SP \s ( ) TAB \t ( ) NL (\n) CR (\r)
Line (+html) 5
Line (+html) 6 WORKING WITH TEXT FILES
Line (+html) 7 Most text files containing text, continue a sentence
Line (+html) 8 across multiple lines, and aren't concerned with
Line (+html) 9 page layout or formatting, beyond sentences and paragraphs.
Line (+html) 10
Line (+html) 11 'Political Jargon'
Line (+html) 12 propaganda
Line (+html) 13 zealot
Line (+html) 14 intelligence
Line (+html) 15 security
Line (+html) 16 [EOF]
Prime Minister Scott Morrison small talking at his own press conference held at Parliament House Canberra, Wednesday August 18, 2021. Image via ABC News.