Convert comma separated string to array and test for entries Convert array into comma separated string
Category: Strings
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
Converting Form Text Fields
filter_var() function Returns the input string filtered into the required typ, or FALSE if it was unable to perform the sanitization (e.g. due to illegal characters etc) See here for all the available filter options. Example – INT Sanitising for HTML from a form POST If server magic quotes is turned on then it will add / […]
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 (\’ […]
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 Convert String to DateTime Display Value As Hex Or the simpler dechex() method […]
Using Strings-Replace and Insert
Replace Case insensitive str_ireplace() is a case-insensitive version of str_replace() Replace whitespace Replace single and multiple occurrences of white space with a comma Pad string to fixed length
Using Strings-Parsing
Convert Comma Separated String To Array Working through each line of a string
Using Strings-Characters
String Characters
Using Strings-Extracting
Substring From start of string From end of string 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 […]
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