«This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing process. Lean Publishing is the act of publishing an ...»
PHP Pandas (PHP7!)
The PHP Programming Language for Everyone.
This book is for sale at http://leanpub.com/php-pandas
This version was published on 2016-04-29
This is a Leanpub book. Leanpub empowers authors and publishers with the Lean
Publishing process. Lean Publishing is the act of publishing an in-progress ebook
using lightweight tools and many iterations to get reader feedback, pivot until you
have the right book and build traction once you do.
© 2014 - 2016 Dayle Rees Tweet This Book!
Please help Dayle Rees by spreading the word about this book on Twitter!
The suggested tweet for this book is:
I’m learning about PHP and Pandas AT THE SAME TIME. You can too! @ http://leanpub.com/php-pandas #PHPPandas @daylerees The suggested hashtag for this book is #PHPPandas.
Find out what other people are saying about the book by clicking on this link to
search for this hashtag on Twitter:
https://twitter.com/search?q=#PHPPandas Also By Dayle Rees Laravel: Code Happy Laravel: Code Happy (ES) Laravel: Code Happy (JP) Laravel: Code Bright Code Happy (ITA) Laravel: Code Bright (ES) Laravel: Code Bright (SR) Laravel: Code Bright (JP) Laravel: Code Bright (IT) Laravel: Code Bright (TR) Türkçe Laravel: Code Bright (PT-BR) Laravel: Code Bright (RU) Laravel: Code Smart PHP Pandas (ES) PHP Pandas (IT) PHP Pandas (FR) PHP Pandas (TR) Contents Acknowledgements.................................. i Errata.......................................... ii Feedback........................................ iii Translations...................................... iv
1. Introduction.................................... 1.....................................
2. Installation 3 Linux......................................... 3 Mac OSX....................................... 4 Windows....................................... 5
i Errata This may be my third book, and my writing will have improved since the last one, but I assure you that there will be many, many errors.
You can help support the title by sending an email with any errors you have found to email@example.com along with the section title.
Errors will be fixed as they are discovered. Fixes will be released within future updates to the book.
1 mailto:firstname.lastname@example.org ii Feedback Likewise, you can send any feedback you may have about the content of the book or otherwise. You can send an email to email@example.com or tweet to @daylerees.
I will endeavour to reply to all mail that I receive.
2 mailto:firstname.lastname@example.org iii Translations If you would like to translate PHP Pandas into your language, then please send an email to email@example.com with your intentions. I will offer a 50/50 split of the profits from the translated copy, which will be the same price as the English copy.
Please note that the book is written in markdown format.
1. Introduction Well hello there! Aren’t you just the most handsome AND/OR beautiful reader on the planet! Well done you for buying PHP Pandas, and for taking the first step towards your career as a world-famous web developer.
Who am I? Well, that’s a simple question! My name’s Dayle, and I’ll be your author for this adventure. I’ve been writing books for beginners for a few years now and have taken many other charming readers like yourself on adventures to learning new skills. We’ll make new discoveries together, and all along the journey, rest assured that I’ll be right by your side.
Why do you write like a crazy person?
Excuse me? Oh, this. Well you see, this is the only way that I know how to write. If you’re looking for a technical book full of science teacher stern-ness (Is that a word?
I hope that’s a word.) then I’m afraid you’ve come to the wrong place. I write my books for people. I like to think that we’re buddies, sitting in the pub, talking about PHP over a pint of Special Bre… Fosters.
The truth is that the beginners that I’ve written for tend to like my writing style.
They’re not looking to gain a maths degree from this book. Instead, they’re looking to learn a thing or two about PHP, and that, I can promise you!
Oh hey, you’ll also notice that we’re talking right now. You don’t get that from other authors do you? You see, I have this magic power that will make you talk to me and ask your questions.
That would be a trade secret. Sorry, we can’t share that just yet, but don’t you feel glad that you get to be a part of this adventure, and not just an observer?
Well now’s about the time where any other book would be telling you about PHP, it’s whole history, its application, its author and about a million other things. Well, we’ve already established that I’m not the most traditional author, and I’m not fond
of such chapters. You’ve bought this book to learn about PHP, so you’ve already built up a little curiosity about the language. I think this is all you’re going to need.
PHP is a programming language that powers most of the sites out there on the big, wide ol’ interwebs. It was originally written by a guy called Rasmus Lerdorf, who can often be seen smiling in pretty much any image you find of him on Google. Now, Rasmus is a great guy, and in my own way I thank him each and every day for this language that has given me a trade, but I think that’s all you need to know about him. Other PHP books would probably be telling you his favorite cereal about now, but instead, how about we jump in and start learning?
This book is for absolute beginners. This means that if you’ve never tried programming before in your life, then you’re in luck, my friend! If you’ve already tried programming, then you’ll do just fine. If you’re a PHP expert, then now’s a time for a refresh of your skills, and maybe you’ll pick up a few tips and tricks along the way.
I’ve been using my girlfriend (no dev experience), my non-technical colleagues, and random people on the street, forcing my book upon them as guinea pigs to see how it goes down with folks that have no prior knowledge of PHP. My little guinea pigs did exceedingly well, so now it’s your turn, squeak squeak!
My goal for this book is for it to become the most fun, factual, and fantastic PHP book that’s on the market. I want it to be the book that gets recommended when someone is about to become a PHP developer. I’ve worked hard to make it accessible to everyone, so if you enjoy this adventure, then please tweet about it, blog about it, buy copies for your friends and family, or just print it out and slap people in the face with it as you pass them on the street.
This book is a syntax book for PHP. It’s not going to teach you how to make websites (I’m working on the title in the series for this). Instead, it’s the first step that will build your foundation knowledge of the language so that when you come to build your first website, you’re gonna be @%Â£ˆ hot, baby!
If you read the book, and you feel like something is missing, that a certain chapter is confusing, or there’s anything else bothering you, then please send me an email to firstname.lastname@example.org to let me know! I’m incredibly responsive (thanks to all my media queries… haha… programmer joke), and I want this book to be perfect for everyone.
If you read the book, and you didn’t find anything wrong, well… send me an email to tell me you enjoyed it! I’d love to hear from you.
Right then, let’s not waste any more time. You’ve got some skills to learn! Flip the page, imagine the Jurassic Park theme when they open the gates and prepare to enter the world of development!
2. Installation Before we begin working with PHP, we must first install it. You see, PHP is an application like any other. It needs to be installed on our system before it can process PHP code.
The method of installation varies greatly depending on the operating system that we are using. For that reason, I’ve provided three different guides for installing PHP.
The first section will explain how to install PHP on a Linux distribution, namely Ubuntu due to its popularity. The second section will explain how to install PHP on an Apple Mac OSX system. Finally, the third section will explain how to install PHP on the Windows operating system.
We’ll only be installing the console version of PHP. We won’t be setting up a web server just yet. We’ll get to that in a later title. The console version of PHP is all we need to get started with our learning process.
Remember, you only need to read the appropriate section for your computer. Once you have PHP installed, go ahead and skip to the next chapter of the book.
Linux The best way to install PHP on a unix-based Linux distribution is to use a package manager. The package manager available depends greatly upon the distribution of Linux that you have chosen. I’ve decided to provide instructions for installing PHP on Ubuntu, one of the most popular distributions of Linux.
Ubuntu uses the apt package manager to install its packages. To install the console version of PHP we need to install the php5-cli package. Let’s do this now. First, open a new terminal. You’ll need to type the following instruction.
1 $ sudo apt-get install php5-cli You don’t need to type the dollar sign; that’s just the terminal prompt to show you that we’re typing it into the console. Once you hit enter, apt will retrieve the PHP application package, and install it for you.
That’s it! You’re done. Well, you should be. Let’s check, shall we? Simply type:
This command is used to show the current version of PHP installed. You should see something similar to the following.
1 PHP 5.5.13 (cli) (built: Jun 5 2014 19:13:23) 2 Copyright (c) 1997-2014 The PHP Group 3 Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies Yours won’t be exactly the same, after all, we’re all different, aren’t we? In the example above, the PHP version is 5.5.13. Hopefully, your PHP version number should be 5.4.0 or greater.
If your version isn’t right then, you’ll have to consult the documentation for your Linux distribution to find out how to install the appropriate version.
Go ahead and skip to the next chapter, you’re done!
Mac OSX On the Macintosh operating system, PHP comes pre-installed. Go ahead, open up the Terminal application and type the following to find the version of PHP you’re using.
Don’t type the dollar sign; that’s the terminal prompt! You should see something similar to the following, but not exactly the same.
1 PHP 5.4.24 (cli) (built: Jan 19 2014 21:32:15) 2 Copyright (c) 1997-2013 The PHP Group 3 Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
brew.sh1 I don’t want to copy the instructions here, as they often change between different releases. Once you have Homebrew installed, it’s time to install a newer version of PHP. I recommend installing version 5.5. You can do this using the following command.
1 $ brew install php55 Next, you need to add the location for this version of PHP to your system PATH variable. Don’t worry, just type the following.
1 $ PATH=~/usr/local/Cellar/php55/5.5.13/bin:$PATH You may need to update the version number to match the version of PHP that Homebrew has installed on your system. Now let’s have another go at checking the version of PHP.
Hopefully, this time, you’ll have a version greater than PHP 5.4. Go ahead and skip to the next chapter.
Windows Installing PHP on Windows is a little more difficult, at least for me it is. I’ve tested the instructions below on my Windows 10 machine, but if you have any difficulty replicating these steps, let me know, and I’ll find someone who’s more Windowssavvy to rewrite this section.
First, head over to:
http://windows.php.net/download Here you’ll want to download the latest PHP 5.4 and above zip archive. Once the archive has been downloaded, you’ll want to extract it to a sensible location. I chose
to extract mine here:
1 cmd.exe Click next, and name your shortcut “PHP”.
Finally, you’ll want to right click your shortcut and click ‘Properties’. On the ‘Shortcut’ tab, change the ‘Start In’ field to match the location where you extracted the PHP archive. Click ‘OK; when done.
Double click on your PHP shortcut and you should be greeted with a command prompt. Type…
1 php -v
..and you should be greeted with the PHP version information. Confirm that the version is greater than or equal to PHP 5.4, and then move to the next chapter.
Once again, sorry for the roughness of this subchapter. I’ve not used Windows as a development machine for some years now. If anyone has a better way of running PHP on Windows, kindly email your instructions to receive your 5 minutes of fame within this chapter!
3. Finding Answers I know. That’s a kinda fluffy title isn’t it? You’re going to have to trust me when I say that this is important stuff. This chapter is about your confidence as an up and coming developer. Learning is hard, but don’t worry; I’m going to help you through this.
Developers are robots.
Why did you decide to pursue development? No, wait! Let me guess. You saw a rockstar PHP developer swagger out of a Limousine into one of New York’s hottest night spots, order five bottles of Cristal and spend the evening chilling with Jay-Z and the ghost of Tupac.