ebook img

PHP: The Ultimate Guide PDF

405 Pages·2022·6.433 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview PHP: The Ultimate Guide

PHP There is no shortage of websites that use the PHP programming language in some or other capacity. PHP (Hypertext Preprocessor) is a server-side scripting lan- guage that allows you to create dynamically-generated web pages. Rasmus Lerdorf created PHP in 1994. PHP works in the backend of a website because it is a server-side technology. This is the part of a website that no one sees. This means that PHP is frequently used to run server-side programs such as data collection and processing and database manage- ment. The fact that PHP is a simple language is one of the key reasons why learning it is a wise investment. PHP was created with the goal of speeding up web develop- ment; therefore, it features a basic syntax that is ideal for beginners. Furthermore, because PHP is a dynamically typed language, there are less restrictions to follow while creating features. The PHP programming language offers a wide range of ap- plications and features, such as authentication, payments, user administration, and other “dynamic” aspects of a website. Efficiency, syntax compatibility, platform independence, error detection, and en- cryption are just a few of the interesting properties of PHP. Why should you learn PHP? PHP developers work with the PHP programming language to create websites, applications, and programs. As a PHP developer, you’ll usually be working in IT companies (all over the world), but there are also a lot of opportunities in design and business. A PHP developer, like any other program- ming/scripting language developer, should be able to work with many languages and ideally have some knowledge of database, web design, or some page format- ting language. This book offers: • A step-by-step approach to problem solving and skill development • A quick run-through of the basic concepts, in the form of a “Crash Course” • Advanced, hands-on core concepts, with a focus on real-world problems • Industry-level coding paradigms and a practice-oriented explanatory approach • Special emphasis on writing clean and optimized code, with additional chapters focused on coding methodology PHP The Ultimate Guide Sufyan bin Uzayr First edition published 2023 by CRC Press 6000 Broken Sound Parkway NW, Suite 300, Boca Raton, FL 33487-2742 and by CRC Press 4 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN CRC Press is an imprint of Taylor & Francis Group, LLC © 2023 Sufyan bin Uzayr Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, access www.copyright.com or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. For works that are not available on CCC please contact mpkbookspermissions@tandf. co.uk Trademark Notice: Product or corporate names may be trademarks or registered trademarks and are used only for identification and explanation without intent to infringe. Library of Congress Cataloging-in-Publication Data Names: Bin Uzayr, Sufyan, author. Title: PHP : the ultimate guide / Sufyan bin Uzayr. Description: First edition. | Boca Raton : CRC Press, 2023. | Includes bibliographical references and index. Identifiers: LCCN 2022025685 (print) | LCCN 2022025686 (ebook) | ISBN 9781032312224 (hardback) | ISBN 9781032311784 (paperback) | ISBN 9781003308669 (ebook) Subjects: LCSH: PHP (Computer program language) | Web site development. Classification: LCC QA76.73.P224 B56 2023 (print) | LCC QA76.73.P224 (ebook) | DDC 005.2/762--dc23/eng/20220919 LC record available at https://lccn.loc.gov/2022025685 LC ebook record available at https://lccn.loc.gov/2022025686 ISBN: 9781032312224 (hbk) ISBN: 9781032311784 (pbk) ISBN: 9781003308669 (ebk) DOI: 10.1201/9781003308669 Typeset in Minion by KnowledgeWorks Global Ltd. Contents Acknowledgments, xxi About the Author, xxiii Chapter 1 ◾ I ntroduction to PHP 1 HISTORY 2 WHY DO WE LEARN PHP? 2 VERSIONS OF PHP 2 PHP 4 What Is PHP? 4 What Can We Do with PHP? 4 Main Components 5 Pros and Cons of PHP 6 Built-in Templating Engine 8 PHP from the Command Line 9 Upgrading PHP in macOS 11 Upgrading PHP in Windows 11 Upgrading PHP in Ubuntu 11 Why Is PHP Still So Widely Used? 12 PHP Prerequisites 13 INSTALLATION OF PHP 13 How to Install PHP on Windows 13 How to Install PHP on Linux 13 Installing PHP on Ubuntu 14 How to Install PHP on macOS 14 v vi ◾ Contents Installing a Text Editor 15 Starting Apache to Run PHP Scripts 15 Place Your Project in the Root Directory of XAMPP 15 Printing Hello PHP on the Web Browser with a PHP File 16 PHP Hello World on the Command Line 16 PHP BASICS 17 Naming Conventions for PHP Variables 19 Echo Statement 22 Displaying Strings with the Print Statement 23 WHAT IS HTML (HYPERTEXT MARKUP LANGUAGE BASICS)? 24 Most Used HTML Tags and HTML Elements 25 Block-Level Elements 25 Inline Elements 25 Using PHP and HTML on a Single Page 26 CSS (CASCADING STYLE SHEETS) 27 What Is CSS? 27 CSS Syntax 27 Using CSS with PHP 28 Data Types 29 Chapter 2 ◾ D ata Types and Operators 43 CODING BUILDING BLOCKS 43 VARIABLES 44 Reading a Variable’s Value 44 Types of Variables 46 PREDEFINED VARIABLES 48 IS PHP A CASE-SENSITIVE LANGUAGE? 49 REGULAR EXPRESSION 50 Why Does Perl Style Regular Expressions? 50 Regular Expression Syntax 51 Character Classes in Regular Expression 51 Contents ◾ vii Built-in Regular Expression Functions in PHP 51 Regular Expression Metacharacters 53 DATA TYPES 53 What Is a Data Type? 53 Integers 55 Strings 55 WHAT IS PHP’S STRING FUNCTION? 56 String Functions 57 ESCAPE SEQUENCES 60 FLOATING POINT NUMBERS OR DOUBLES 61 Booleans 61 Arrays 62 Operator Keywords 66 Objects 66 NULL 67 Resources 67 Typecasting 68 Automatic Type Conversion 70 IMPLICIT AND EXPLICIT CASTING 70 EXPRESSIONS 70 Expressions with ++ and −− Operators 71 Expressions with Ternary Conditional Operator 71 OPERATORS 72 CHAPTER SUMMARY 86 Chapter 3 ◾ C ontrol Statements 87 INTRODUCTION TO CONTROL STATEMENTS 87 LIST OF KEYWORDS AVAILABLE IN PHP 89 What Is a Keyword? 89 Operands Lvalue and Rvalue 90 Lvalue 90 Rvalue 90 viii ◾ Contents LIST OF CONTROL STATEMENTS 91 The if Statement 91 The else Statement 91 else-if Statement 92 switch Statement 93 The ? Operator 95 Expressions with the Ternary Conditional Operator 95 Alternative Syntax for Control Structures (if, else-if) 96 while Loop 96 do-while Loop 98 for Loop 98 Breaking Out of the Loop 99 foreach 100 Continue 101 Break and Continue in while Loops 101 match 102 declare 103 return Statement 104 require Statement 104 include Statement 104 require_once Statement 105 include_once Statement 105 goto Operator 106 WHAT IS THE BOOLEAN EXPRESSION IN PHP? 106 Boolean Constant 106 CHAPTER SUMMARY 106 Chapter 4 ◾ P HP Functions 107 FUNCTIONS 107 DECLARING A FUNCTION 108 function return Statement 109 function with Default Argument Value 110 Contents ◾ ix The function within Another function 110 The return Statement 111 Scope and the Global Statement 112 Working with print_r() 113 How to Pass PHP Variables by Reference 114 Pass by Reference 115 VARIABLE-LENGTH ARGUMENT FUNCTION 115 Built-in Functions in PHP 116 Recursion 117 Dynamic Function Calls 118 Callable 119 TYPES OF FUNCTIONS 119 Language Constructs 122 Function Handling Functions 123 Flag Parameters 125 INTRODUCTION TO PHP USER DEFINED FUNCTIONS 126 Namespace PHP Functions 126 PHP KEYWORDS AND IDENTIFIERS TUTORIAL 128 What Is an Identifier? 128 Rules for Naming Identifiers 128 Identifier Casing Conventions 130 TYPE HINTS 131 How to Use Array-Type Hinting 131 How to Use Object-Type Hinting 132 Does PHP Support Any Type Hinting for Some Basic Data Types? 133 THE SPLAT OPERATOR IN PHP 133 SIGNATURE 134 “PARAMETER” VS. “ARGUMENT” 135 Variable Functions 136 Anonymous Functions (Lambda) 137 Assigning the Anonymous Function to Variables 138 Using an Anonymous Function as the Callback 138

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.