Skip to content

Instantly share code, notes, and snippets.

View glagola's full-sized avatar

Igor Glagola glagola

View GitHub Profile
<?php
function mysql_escape_mimic($inp)
{
if(!empty($inp) && is_string($inp)) {
return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $inp);
}
return $inp;
}
@glagola
glagola / gist:2299962
Created April 4, 2012 09:32
utf8_strrev($str)
<?php
function utf8_strrev($str) {
return iconv("UTF-16LE", "UTF-8", strrev(iconv("UTF-8", "UTF-16BE", $str)));
}
@glagola
glagola / gist:1884392
Created February 22, 2012 11:38
Generate unique name of the new file by full path to the file
<?php
function genUniqueFileName($fullPathToFile)
{
$pathInfo = pathinfo($fullPathToFile);
$k = 1;
$uniquePath = $fullPathToFile;
while (file_exists($uniquePath)) {
$uniquePath = $pathInfo['dirname'] . '/' . $pathInfo['filename'] . '-' . $k++ . '.' . $pathInfo['extension'];
}