In this article you will learn about the shortcuts and things to notice while writing PHP Code
Also PHP Should Be Already Installed on your PC, Device, Server, Sandbox or Virtual Machine ( Whatever You are using Maybe Toaster Also 😅 Don't Know What will Be Machine ).
The Given Post is about PHP 8 and Above.
PHP Code is created under an HTML Template. Actually PHP is Used like additional element of HTML.
PHP Oneliner echo Function Shortcut
So while writing some code like
<?php echo "Hello World" ?> oneliner code we can use shortcut like below.
<div> This PHP One Line Code echo "Hello World" And This One Line PHP Code are similar. "Hello World" and Also Shows the same result </div>
This shortcut is only for echo function not for any other functions.
PHP running as alone
Just if your learning only the PHP, then for starters there is no need of installing or using apache, mysql, phpmyadmin directly from start you can still learn starting concepts without them.
Given Below is the Command for starting Built-in server of php in Command-line is given below.
php index.php -S 127.0.0.1:8000 -t .
For Online Code Editor Ide It is
0.0.0.0:8000 for using instead of
While ending the PHP File No Need to add last
?> in some Situations
If your code does not have any data related to html after the PHP Closing Tag At Last then also don't add the
?> tag of php.
Reason Maybe Like you maybe not always maybe you will have issues while importing one php file with
?> at to another then the another php file will expect no end tag at last of php.
For Example Given Below.
echo "Hello World"
if we tried to import this file in another file like given below
<div> require_once("./first.php"); echo "This part will not parse as php code"; And In Some OS it shows errors
here when we import
first.php our php code part of
second.php will close while importing and program below that will have some issues while running.
If you found this useful then please share this and follow me! Also check out Buy Me A Coffee if you want to support me on a new level!
Cover Image Credits
Image Available at https://unsplash.com/photos/2Rd-hwT2xQ0
Thanks for reading untill now.