Skip to content

Instantly share code, notes, and snippets.

View muratpurc's full-sized avatar

Murat Purç muratpurc

View GitHub Profile
@muratpurc
muratpurc / gist:1234497
Created September 22, 2011 10:28
PHP: Remove unwanted characters like < > " from passed path value
/**
* Removes unwanted characters like < > " from passed path value
*
* @param string $value The value to clean
* @param string $replaceWith The replacement (empty by default)
* @return string Cleaned path value
*/
function mp_getCleanPathVar($value, $replaceWith = '')
{
$value = (string) trim($value);
@muratpurc
muratpurc / gist:1234489
Created September 22, 2011 10:23
PHP: Debug content of passed variable
/**
* Dumps the content of passed variable and returns the result.
*
* @param mixed $var The variable
* @param string $label Additional text to describe the variable
* @param bool $formatted Flag to return formated information
* return string
*/
function mp_dumpVar($var, $label = '', $formatted = true) {
$dump = ($label !== '') ? $label . ":\n" : '';
@muratpurc
muratpurc / gist:1234477
Created September 22, 2011 10:16
PHP: Extended ressource/file/url link check with redirect handling (Linkchecker)
/**
* Checks HTTP Links.
* Based on function phpLinkCheck from Johannes Froemter <[email protected]>, 2001-04-14.
*
* Usage:
* <code>
* $url = 'http://www.google.de/?q=foobar';
* $res = mp_linkCheck($url);
*
* // key 'Status-Code' will contain the HTTP status code (e.g. 200 or 404).
@muratpurc
muratpurc / gist:1234472
Created September 22, 2011 10:13
PHP: Check the existance of an ressource/file/url on a host (Linkchecker)
/**
* Checks the existance of an ressource/file/url on a host (Linkchecker).
*
* Usage:
* <code>
* $url = 'http://www.google.de/?q=foobar';
* $opt = array('timeout' => 3);
* $result = mp_urlCheck($url, $opt);
* if ($result == false) {
* echo 'ERROR: Errornumber: ' . $opt['errno'] . ', Errormessage: ' . $opt['errstr'];
@muratpurc
muratpurc / gist:1234469
Created September 22, 2011 10:12
PHP: Change mode of folders/files recursively
/**
* Changes mode of folders/files recursively.
*
* @param string $dir The directory to change mode recursively
* @param int $dirMode Folder permissions to set
* @param int $fileMode File permissions to set
* @return void
*/
function mp_recursiveChmod($dir, $dirMode=0775, $fileMode=0775)
{
@muratpurc
muratpurc / gist:1234410
Created September 22, 2011 09:29
PHP: Traverse object inheritance, creates object tree using the ReflectionClass.
/**
* Builds the class tree, calls itself recursively, if a parent exists.
*
* @param string $name The name of class to create the tree from
* @param int $level Tree level
* @return string The string representation of the tree
*/
function buildClassTree($name, $level=0){
$prefix = str_repeat(' ', ($level * 2));
$tree .= $prefix . $name . "\n";
@muratpurc
muratpurc / gist:1234383
Created September 22, 2011 09:02
JS: JSDOC plugin to use for extended documentations
/**
* Replaces occurance of userdefined docblocks within js sourcecode against HTML tags <pre><code>...</pre></code>
*
* Example:
* @xcode
* var foobar = 123456;
* /@xcode
*
* Will be replaced against:
* <pre><code>