DEV Community

PHP Functions every beginner should know.

RiversideRocks on August 08, 2020

PHP is one of the most popular languages for building websites. In fact, you probably used it today if you visited a Wordpress site or Facebook. H...
Collapse
 
fjones profile image
FJones

Some additions:
Avoid exec if possible! A great many use-cases have dedicated native wrappers for system calls (e.g. mkdir). Very rarely will you be forced to actually execute shell commands, and when you are, you'll have to struggle with the output of that shell call as well.

file_get_contents for HTTP requests is also best discouraged. It's great for local disk, but ext-curl provides a much better wrapper around curl.

Collapse
 
cchana profile image
Charanjit Chana

I had completely forgotten about htmlspecialchars(), would have saved me a lot of time had I read this yesterday morning :D

Collapse
 
peter279k profile image
peter279k

The yet another function about preventing XSS is htmlentities() :).

Collapse
 
phantas0s profile image
Matthieu Cneude • Edited

What a beginner should know is how to search effectively the documentation / on Google.

Collapse
 
riversiderocks profile image
RiversideRocks

And how to use Stackoverflow

 
leohajder profile image
Leo Hajder

I always start with the official docs. php.net/manual/en/features.command... You can write php scripts and run them like php myfile.php with arguments, options etc.

Collapse
 
leohajder profile image
Leo Hajder

You can use PHP for CLI applications too.

Collapse
 
leohajder profile image
Leo Hajder

... and all the mb_* versions of string functions. You might not even know you're deling with an encoding with multi-byte characters. Basically, if the normal string functions return wrong or strange results, try adding the mb_ in front of them.

Collapse
 
vonbusing profile image
Miro von Busing

No. Don't try that at home.

Collapse
 
scorp13 profile image
scorp13
 
riversiderocks profile image
RiversideRocks

If you use windows, download XAMPP:
apachefriends.org/index.html

If you use Linux, download Apache:
sudo apt-get install apache2

Collapse
 
dawx profile image
Dawx

You can set up local server