This is a super simple command but there is something about the following sequence of characters that I simply cannot retain in my brain.
Continue reading
Debugging PHP by monitoring errors in terminal
4
This is a super simple command but there is something about the following sequence of characters that I simply cannot retain in my brain.
Continue reading
Simple function to check if XML is valid. It just loads the XML into DOMDocument and checks for errors.
/**
* Takes XML string and returns a boolean result where valid XML returns true
*/
function is_valid_xml ( $xml ) {
libxml_use_internal_errors( true );
$doc = new DOMDocument('1.0', 'utf-8');
$doc->loadXML( $xml );
$errors = libxml_get_errors();
return empty( $errors );
}
Here is a function to find duplicate items in an array.
/**
* Takes an array and returns an array of duplicate items
*/
function get_duplicates( $array ) {
return array_unique( array_diff_assoc( $array, array_unique( $array ) ) );
}
Neat way of removing excess whitespace and tabbing from strings.
$string = "Tom\tThumb\t is sooooooo\t\t\tdumb"; $string = preg_replace( '/\s+/', ' ', $string ); echo $string; //will echo "Tom Thumb is sooooooo dumb"
If you want to convert comma separated values into an associated array, then use the following code.
Continue reading
Excellent post from one of my favourite sites – Become a command line ninja with these time saving shortcuts
Simple one. If you need to add/remove escape slashes to/from a string, use the following code.
Continue reading