The php docs page on htmlspecialchars mentions:
The default is ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401.
My knowledge of | in programming documentations is only this MDN explanation of its use in css docs. This seems to be not applicable in php documentation, as $flags can be left blank in htmlspecialchars().
In php htmlspecialchars, I noticed that, without mentioning the flag, it does not convert single quotes into '. This certainly implies, ENT_QUOTES is not the default value.
So, what does | mean in php documentation, and what is the default value of $flags in htmlspecialchars?
It is a bitwise OR.
It combines a set of options (internally expressed as numbers) into a single value that means "All of these options combined".
Let's look at how that works.
Consider that you might have flags:
In binary that would be
So if you had
You'd get
101and that could be compared successfully to FLAG_A or FLAG_C.In decimal it is represented as 5, but the point of flags like these is to store a combination of yes/no options in a compact form.
Here's a practical example in JS (this kind of bitwise logic is foundational to computer programming so works the same in most languages).
Re your comment
The actual values don't matter. You can consider them internal to PHP. You only need to worry about the constants.
ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401is the default, so those three options are all turned on.The documentation tells you that
ENT_QUOTESmeans "Will convert both double and single quotes..". So you know that that is how the function will work by default. (Along with whatever it says about the other two options that are turned on).No. If you pass a different set of values for the options, you change the defaults.
If you say
ENT_COMPATthen that turnsENT_COMPATon and everything else off.