Skip to content

Instantly share code, notes, and snippets.

View mikkohei13's full-sized avatar

Mikko Heikkinen mikkohei13

View GitHub Profile
@mikkohei13
mikkohei13 / checkUTF8BOM.php
Created November 27, 2012 11:09
Checks if file is UTF-8 and without BOM
/*
Thanks to
http://www.php.net/manual/en/function.mb-detect-encoding.php#91051
http://stackoverflow.com/questions/8907196/check-if-csv-file-is-in-utf-8-with-php
*/
if (! mb_check_encoding($data, 'UTF-8')) {
exit("Not UTF-8");
}
else
@mikkohei13
mikkohei13 / Converts XML to array
Last active October 12, 2015 02:58
XML to Array
// Source: http://www.php.net/manual/en/book.simplexml.php#108035
function toArray(SimpleXMLElement $xml) {
$array = (array)$xml;
foreach ( array_slice($array, 0) as $key => $value ) {
if ( $value instanceof SimpleXMLElement ) {
$array[$key] = empty($value) ? NULL : toArray($value);
}
}
@mikkohei13
mikkohei13 / isinvalid.php
Created October 24, 2012 07:52
Regular expression validator: returns TRUE if subject does not fully match pattern
function isInvalid($subject, $pattern)
{
preg_match($pattern, $subject, $matches);
if ($matches[0] == $subject)
{
return FALSE;
}
else
{
return TRUE;