mirror of
https://github.com/restoreddev/phpapprentice.git
synced 2025-08-02 12:57:59 +02:00
Merge pull request #24 from restoreddev/develop
Tweaking styles and adding to Basics chapter
This commit is contained in:
@@ -90,7 +90,7 @@ button:hover .icon svg {
|
||||
.button {
|
||||
background-color: $primary-color;
|
||||
color: $white;
|
||||
padding: 0.5em 1em;
|
||||
padding: 0.25em 0.75em;
|
||||
border-radius: 2em;
|
||||
display: inline-block;
|
||||
}
|
||||
@@ -207,9 +207,12 @@ button:hover .icon svg {
|
||||
width: 150px;
|
||||
height: 100px;
|
||||
}
|
||||
.home-buttons {
|
||||
margin-top: 1.5em;
|
||||
}
|
||||
.home-buttons .menu {
|
||||
display: inline-block;
|
||||
padding: 0.5em 1em;
|
||||
padding: 0.25em 0.75em;
|
||||
}
|
||||
.menu {
|
||||
margin-bottom: 1.5em;
|
||||
|
@@ -8,19 +8,15 @@
|
||||
<h3 class="home-subtitle">A site for learning how to use PHP</h3>
|
||||
</div>
|
||||
<p>
|
||||
The goal of PHP Apprentice is to be an easy to understand resource for learning how to write good code in the PHP programming language. There are a lot of PHP tutorials on the internet that use outdated libraries, insecure programming practices or inefficient code. I want this site to show how to write PHP code with quality.
|
||||
The goal of PHP Apprentice is to be an easy to understand resource for learning how to write good code in the PHP programming language. There are a lot of PHP tutorials on the internet that use outdated practices or insecure code. I want this site to show how to write PHP code with quality.
|
||||
</p>
|
||||
<p>
|
||||
The site currently has content for learning the basics of PHP. In the future, more pages will be added for more advanced topics like building websites, database integration and security.
|
||||
PHP Apprentice is for beginners and for developers who already know some PHP. The site currently has content for learning the basics of PHP. In the future, more pages will be added for more advanced topics like building websites, database integration and security.
|
||||
</p>
|
||||
<p>
|
||||
PHP Apprentice is currently a work in progress. If you would like to contribute or request a certain discussion topic, check out the <a href="https://github.com/restoreddev/phpapprentice" target="_blank">GitHub repository</a>.
|
||||
</p>
|
||||
<p>
|
||||
To get started, you will need to <a href="<?php echo page_path('installing-php') ?>">install</a> PHP, have a text editor and open your terminal.
|
||||
Each example in PHP Apprentice can by typed into a PHP file and executed in the terminal.
|
||||
Let's get started! 😃
|
||||
PHP Apprentice is currently a work in progress. If you would like to give feedback or request a certain discussion topic, check out the <a href="https://github.com/restoreddev/phpapprentice" target="_blank">GitHub repository</a>.
|
||||
</p>
|
||||
<p>Let's get started!</p>
|
||||
<div class="home-buttons">
|
||||
<a href="<?= page_path('basics') ?>" class="button">
|
||||
<div class="icon"><?= icon('book-reference') ?></div>
|
||||
|
@@ -1,8 +1,10 @@
|
||||
If you want to follow along by writing code, start by downloading a code editor. I recommend
|
||||
[Visual Studio Code](https://code.visualstudio.com/) or [Sublime Text](https://www.sublimetext.com/).
|
||||
Next, create a new file in your editor called `basics.php` and save it anywhere on your computer like a folder
|
||||
in your documents called `phpapprentice`. Now, we can write some PHP.
|
||||
|
||||
In the tradition of our ancestors, let's start with a hello world program.
|
||||
All PHP files must start with a `<?php` tag unless it is for a html template.
|
||||
(We will learn about html templates later.)
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
@@ -16,12 +18,10 @@ First, the echo keyword tells PHP to output some text.
|
||||
echo "I am some text\n";
|
||||
```
|
||||
|
||||
Second, PHP stores text in strings.
|
||||
|
||||
To write a string, you surround letters with single or double quotes.
|
||||
Second, PHP stores text in strings. To write a string, you surround letters with single or double quotes.
|
||||
Double quoted strings can hold special characters like `\n` which tells PHP to start a new line.
|
||||
```php
|
||||
"\nI am a string on a new line";
|
||||
echo "I am a string on a new line\n";
|
||||
```
|
||||
|
||||
Third, all lines of code in PHP must end in a semi-colon.
|
||||
@@ -31,5 +31,21 @@ echo "No semi-colon is a no-no\n";
|
||||
|
||||
Using semi-colons means we can write multiple statements on one line.
|
||||
```php
|
||||
echo "Hello"; echo " World\n";
|
||||
echo "PHP"; echo " Apprentice\n";
|
||||
```
|
||||
|
||||
To execute the code you have written, make sure you have [PHP installed](/installing-php.html).
|
||||
Then, open a terminal app, either Terminal on MacOS or Powershell on Windows. In the terminal,
|
||||
open the folder where you created the `basics.php` file using `cd`. For example, on Windows run `cd C:\%userprofile%\Documents\phpapprentice` and on Mac run `cd ~/Documents/phpapprentice`. Finally, you can execute the file by running `php basics.php`.
|
||||
|
||||
In your terminal, you should see:
|
||||
```bash
|
||||
Hello World!
|
||||
I am some text
|
||||
I am a string on a new line.
|
||||
No semi-colon is a no-no
|
||||
PHP Apprentice
|
||||
```
|
||||
|
||||
With any code that we explore in future chapters, I recommend writing a PHP file for it.
|
||||
It is a great way to get some practice with the language.
|
||||
|
Reference in New Issue
Block a user