Compare Strings

== vs === – IMPORTANT FOR STRINGS!!!!! When comparing a string to an integer the string is evaluated as 0!! evaluates true because first “ABC” is converted to integer and becomes 0 then it is compared to 0. Use === if you are comparing non strings to a string value

Read More

Converting Form Text Fields

Sanitising for HTML from a form POST If server magic quotes is turned on then it will add / before a single and double quotes in the text, so strip them out first: \n new line characters will still be stored as \n (htmlspecialchars() doens’t convert them to <be>). You can convert them now using […]

Read More

Heredoc string

You can use the <<< sequence like this (this is called a Heredoc string): The terminating marker must be at the start of a line and the only thing on the line (no comment or even whitespace after it!!!) The advantage of this is that there is no need for line breaks, escape characters (\’ […]

Read More

Using Strings-Values

Convert to int Formatting Numeric Values Leading Zeros Decimal Places Displaying Date And Time Current Date and Time Values you use: click here Get hours now From A String Variable (e.g. a MySQL result) Display as UTC Values you use: click here Display Value As Hex Or the simpler dechex() method but without forcing the […]

Read More

Using Strings-Extracting

Substring Get String Before & After Character/String If Present Remove First Word In A String Remove Last Word In A String Get String Before First Occurrence Of A String Get String After First Occurrence Of A String Neat way of getting just the string after the search string: Getting String Between Strings

Read More

Using Strings-Searching Strings

Does String Contain String strpos() strpos ($haystack , $needle , $offset = 0 ) Returns False on no match or first occurrence index (from 0) on match Does string start with Alternative substring compare method

Read More