This I didn’t actually know until just a little while ago.
Now I know \n means new line, \r means carriage return and \t means tab, but what I couldn’t figure out is why I couldn’t get PHP to spit them out correctly in my PHP echo statements. And I was like using
and everything! ;)
The problem?
Well it turns out I didn’t know that there actually is a pretty big difference between using single and double quotation marks to denote strings in PHP! And apparently this is a pretty big issue because most self-taught guys (like myself) really kind of gloss over this point in the basics.
Using single quotes essentially tells PHP that this is a string, use it as a string. Double quotes on the other hand tells PHP to parse the string, look for possible variable matches and escaping characters (like
for example) and then obviously substitute/operate on them as required.
So needless to say, using single quotes (with concatenation in of variables if required) in your script is far quicker and more efficient than using double quotes, which really should on be used when you DO actually need to make use of escaped characters and the like.
Seriously. You learn something new every day.
You might also enjoy:
-
Annoyingly, my PHP json_decode function was not working on my ajax pushed data, using the Javascript function json.stringify to post the data to the script ...
-
Sometimes you need to store things like file paths into a database table during your PHP script's execution. However, on going back to the database after ru ...
-
It is sometimes a good idea to obfuscate your query strings between web scripts, if only to prevent user URL tampering that could effect the outcome of your ...
-
While most modern programming languages do feature a function that allows you to insert one string into another string at any given position, PHP for some o ...
-
While the new Microsoft Office Word 2007 has simply made things a whole lot easier for entry-level users as a whole, it can be more than a little frustratin ...