Simplified PHP
()
About this ebook
What this book is about, is not to teach you how to program in PHP but to show you more structured way to improve what you're already doing by reusing code and building better functions that will be useful in the long term. Beyond that, working with code that is easily readable and understandable by just applying a few programming practices. This doesn't produce the most efficient code but it does allow you to completely understand what you've written before, to easily make changes at any time.
Probably most importantly providing a different aspect to how you program.
It's time to stop reinventing the wheel every time you have to build a new website. As well to provided list of commands that you are likely to use every day including how to use them and what the parameters mean.
James Blanchette
He has spent more than 35 years in the computer industry, developing and programming in multiple programming languages. Currently he is working mostly in Website and Application development for Android systems. Website design with full PHP backend for dynamic websites.
Read more from James Blanchette
Plato Raw Rating: 0 out of 5 stars0 ratingsTheO Rating: 0 out of 5 stars0 ratingsSet Up your own Twitter APP Rating: 0 out of 5 stars0 ratings
Related to Simplified PHP
Related ebooks
PHP programming Rating: 0 out of 5 stars0 ratingsBeginning PHP: Master the latest features of PHP 7 and fully embrace modern PHP development Rating: 0 out of 5 stars0 ratingsRapid Application Development With CakePHP Rating: 0 out of 5 stars0 ratingsAn Introduction to Programming in PHP: Stomping Zombies with Variables, Loops, Functions and More: Undead Institute, #14 Rating: 0 out of 5 stars0 ratingsIntroduction to PHP, Part 5, Second Edition Rating: 0 out of 5 stars0 ratingsIntroduction to PHP, Part 3, Second Edition Rating: 0 out of 5 stars0 ratingsPHP Programming For Beginners: The Simple Guide to Learning PHP Fast! Rating: 0 out of 5 stars0 ratingsPHP Examples, Part 2 Rating: 1 out of 5 stars1/5Introduction to PHP, Part 4, Second Edition Rating: 0 out of 5 stars0 ratingsIntroduction to PHP, Part 2, Second Edition Rating: 0 out of 5 stars0 ratingsUltimate Tailwind CSS Handbook: Build sleek and modern websites with immersive UIs using Tailwind CSS Rating: 0 out of 5 stars0 ratingsInstant Play Framework Starter Rating: 0 out of 5 stars0 ratingsCakePHP 1.3 Application Development Cookbook Rating: 0 out of 5 stars0 ratingsWordPress 3.0 jQuery Rating: 0 out of 5 stars0 ratingsInstant Magento Shipping How-To Rating: 0 out of 5 stars0 ratingsApache Solr PHP Integration Rating: 0 out of 5 stars0 ratingsjQuery 1.3 with PHP Rating: 0 out of 5 stars0 ratingsBeginning PHP5, Apache, and MySQL Web Development Rating: 0 out of 5 stars0 ratingsLearn SQL Database Programming: Query and manipulate databases from popular relational database servers using SQL Rating: 0 out of 5 stars0 ratingsMastering Magento Theme Design Rating: 0 out of 5 stars0 ratingsPHP Mastery: Crafting Dynamic Web Solutions Rating: 0 out of 5 stars0 ratingsBeginning DotNetNuke Skinning and Design Rating: 0 out of 5 stars0 ratingsPHP 5 CMS Framework Development - 2nd Edition Rating: 0 out of 5 stars0 ratingsMastering Play Framework for Scala Rating: 0 out of 5 stars0 ratingsMastering Java: A Comprehensive Guide to Programming Excellence Category Rating: 0 out of 5 stars0 ratingsLearning Magento Theme Development Rating: 0 out of 5 stars0 ratingsFrontend Software Development and Best Practices: A Concise Guide Rating: 5 out of 5 stars5/5AJAX Interview Questions, Answers, and Explanations: AJAX Certification Review Rating: 0 out of 5 stars0 ratingsLearn Angular: 4 Angular Projects Rating: 0 out of 5 stars0 ratings
Programming For You
Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsCoding All-in-One For Dummies Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Beginning Programming with C++ For Dummies Rating: 4 out of 5 stars4/5C Programming For Beginners: The Simple Guide to Learning C Programming Language Fast! Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Problem Solving in C and Python: Programming Exercises and Solutions, Part 1 Rating: 5 out of 5 stars5/5Code like a Pro in C# Rating: 0 out of 5 stars0 ratingsSpies, Lies, and Algorithms: The History and Future of American Intelligence Rating: 4 out of 5 stars4/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5C All-in-One Desk Reference For Dummies Rating: 5 out of 5 stars5/5
Reviews for Simplified PHP
0 ratings0 reviews
Book preview
Simplified PHP - James Blanchette
Simplified PHP
James Blanchette PhD
––––––––
copyright James Blanchette 2018
Published by Spangaloo Publishing
––––––––
Spangaloo Edition
Standard Copyright eBooks are strictly protected works. You must not perform any actions, including copying, printing and distribution without the author’s written or printed consent (the author may have already granted certain terms in a statement within this book.) Some of our eBooks are cleared for personal printing if this option has been enabled, The unauthorized sale of Copyright works in any form is illegal.
Names and companies are used for reference purposes only and are not intended to be an endorsement
Cover Design: James Bryron Love
Ebook Formatting : Alan Thriete
http://spangaloo.com
Contents
Preface
What is PHP
PHP Basics
IF ELSE ELSEIF
WHILE
DO WHILE
FOR NEXT
FOREACH
SWITCH
TRIM
STRINGS
str_replace
explode
String Change case strtolower() strtoupper() ucfirst() ucwords()
substr
strpos
strlen
strstr
ARRAYS
ISSET
COUNT
TIME
SESSIONS
MYSqli
MySqli Connect
Mysqli Query
Classes
Some simple rules
Reusable pages
Reusable code
Generic functions
HTML with PHP
CSS and PHP
Controlling User Input
Security
Harden Your PHP
Sessions
Website
Database
Building Websites
AJAX
Error Control
––––––––
Mysql Data Types
MYSQL Keywords and Reserved Words
List of Keywords PHP
String Functions List
Time Zone List
Date Format Characters List
Other Books
Preface
What this book is about, is not to teach you how to program in PHP but to show you more structured way to improve what you’re already doing by reusing code and building better functions that will be useful in the long term. Beyond that, working with code that is easily readable and understandable by just applying a few programming practices. This doesn’t produce the most efficient code but it does allow you to completely understand what you’ve written before, to easily make changes at any time.
Probably most importantly providing a different aspect to how you program.
It’s time to stop reinventing the wheel every time you have to build a new website. As well to provided list of commands that you are likely to use every day including how to use them and what the parameters mean.
What is PHP?
From the preface of the manual:
PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.
––––––––
What does PHP stand for?
PHP stands for PHP: Hypertext Preprocessor. This confuses many people because the first word of the acronym is the acronym. This type of acronym is called a recursive acronym.
I’d like to start by explaining that PHP is an incredibly complex language, capable of most if not all the things that you would like it to do.
Everything from robust classes to give you object orientated programming, to simply displaying the date on a website. PHP can be utilized using Ajax for dynamic web development that encompasses both server-side and client-side.
Most problems stem from trying to fix code that you wrote six months ago. As you look at it is more difficult to glean any kind of reference to what you are thinking about at the time.
Embedding comments in your files is something that is not only helpful, it is absolutely necessary especially if you need to do some rewrites.
PHP is constantly evolving and as such various commands are either improved and changed or disregarded completely and no longer available.
Simplifying the writing of PHP, to make it easier to understand in the future is what we are going to be talking about. Simplifying the PHP does not make it as efficient as some more complicated versions of the code can be, however readability is what we’re after.
Bear in mind that simplifying PHP is not just about writing readable code, it’s about being able to reuse the code over and over again thus saving you time, energy and frustration.
PHP Basics
This chapter will outline some of the basics of PHP including some of the necessary commands and keywords that you will use it continuously throughout your PHP programming. You can skip this particular chapter if your are you familiar with most of the PHP concepts.
IF ELSE ELSEIF
The if construct or command is available in almost all programming languages. It allows for conditional execution of code. The IF structure itself is similar to that of C programming language.
The expression is evaluated to its boolean value and if the expression is true then the rest of the statement is executed, if it is false that everything gets ignored.
if (expr)
statement
if (condition) {
code to be executed if condition is true;
}
An example.
$t = date(H
);
if ($t <= 20
) {
echo Have a good day!
;
}else{
echo Have a good night!
;
}
By using the else command when the expression is false, we can still do something. It could be to generate an error or output something completely different.
ELSEIF
if (condition) {
code to be executed if this condition is true
} elseif (condition) {
code to be executed if this condition is true;
} else {
code to be executed if all conditions are false;
}
––––––––
if ( isset ($_SERVER[HTTP_X_FORWARDED
])){
$testip = $_SERVER[HTTP_X_FORWARDED
];
}elseif ( isset ($_SERVER[HTTP_FORWARDED_FOR
])){
$testip = $_SERVER[HTTP_FORWARDED_FOR
];
}elseif ( isset ($_SERVER[HTTP_FORWARDED
])){
$testip = $_SERVER[HTTP_FORWARDED
];
}elseif ( isset ($_SERVER[HTTP_X_FORWARDED
])){
$testip = $_SERVER[HTTP_X_FORWARDED
];
}else{
if ( isset ($_SERVER[REMOTE_ADDR
])){
$testip = $_SERVER[REMOTE_ADDR
];}
}
––––––––
The above code steps through a list of possibilities to grab the user’s IP address.
$t = date(H
);
if ($t <= 10
) {
echo Have a good morning!
;
} elseif ($t <= 20
) {
echo Have a good day!
;
} else {
echo Have a good night!
;
}
Special characters.
The IF statement generally uses two characters in determining whether a statement is true or not. If it is going to equal something then best practice suggest you use a double Equal sign ==. There are other characters involved and well as can be seen in the above code using the less than <= but also available is the greater than >=. Others are using both greater than and less than two equate to not equal <> as well this != also means not equal to.
There are other ways to express the same thing in a shorter version. Consider this.
––––––––
if ($condition) {
$result = 'foo'
} else {
$result = 'bar'
}
can also be expressed this way.
$result = $condition ? 'foo' : 'bar';
If this $condition evaluates to true, the lefthand operand will be assigned to $result. If the condition evaluates to false, the righthand will be used. As well you can use additional equations as part of a single if statement by using logical operators. You have and, or, XOR,&& || and ! Each performing its own way.
if (x==1 and y=2){
}
if (x==1 && y=2){
}
if (x==1 or y=2){
}
Special conditions also exist , using the triple equal is not the same as using a double equal
if($a == $b){
// do something
}
Equal true: if $a is equal to $b, after type juggling.
if($a === $b){
// do something
}
Identical true: if $a is equal to $b, and they are of the same type. So what that means is that if both are integers or perhaps floating-point as well as a string type they can be compared by their type to evaluate whether they’re true or not. If you mix an imager with a string and use the triple equal it will always be false.
WHILE
The while command is used in loops and will continue to loop as long as a given condition is true. It also follows a similar structure to the IF command.
while (expr)
statement
––––––––
The meaning of the while command is simple PHP will execute the necessary men's repeatedly as long as the while at expression evaluates to true. The value is checked at the beginning of the loop so even if the value changes during execution execution will not stop until the end of the iteration.
If the expression evaluates to false then the while command will not execute any code.
––––––––
$x = 1;
while ($x <= 10) {
echo $x++;
/* the printed value would be $x before the increment (post-increment) */
}
As well without curly braces.
$x = 1;
while ($x <= 10):
echo $x;
$x++;
endwhile;
––––––––
Database access heavily utilizes the while command as seen below.
––––––––
$querysub = select * from sometable order by rand() limit 5
;
$resultSub = mysqli_query($con,$querysub) or die(mysqli_error($con)) ;
if(mysqli_num_rows($resultSub)>=1)
{
//$output[];