PHP Related Small Tips for Improving the Speed of Writing Program

PHP Tutorials by shriekdj Series

ยท

2 min read

Preface

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
<?php 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 localhost:8000.


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.

first.php

<?php echo "Hello World" ?>

if we tried to import this file in another file like given below

other.php

<div>
<?php
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.


Conclusion

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!

Buy me a coffee


Cover Image Credits

The Given Image is Provided by Ben Griffiths on Unsplash.

Image Available at https://unsplash.com/photos/2Rd-hwT2xQ0

Thanks for reading untill now.

Bye ๐Ÿ‘‹.

Did you find this article valuable?

Support Shrikant Dhayje by becoming a sponsor. Any amount is appreciated!

ย