Open terminal
sudo add-apt-repository ppa:webupd8team/sublime-text-2 sudo apt-get update sudo apt-get install sublime-text
<?php | |
$html = '<img class="medium" src="/images/image.jpg" width="100" height="75">'; | |
// get attrs | |
preg_match_all('~([\w]+?)="(.*?)"~i', $html, $m); | |
$attrs = array_combine($m[1], $m[2]); | |
print_r($attrs); | |
// result |
<?php | |
function avg(){ | |
return array_sum(func_get_args()) / func_num_args(); | |
} | |
function avgr($a){ | |
return array_sum($a) / count($a); | |
} | |
if (typeof RegExp.prototype.matchAll !== "function") { | |
RegExp.prototype.matchAll = function(v) { | |
var tmp = ""+ this, // So this.toString | |
src = tmp.lastIndexOf("/"), | |
pattern = tmp.substring(1, src), | |
flags = tmp.substring(src + 1, tmp.length); | |
// Never forget "g", that prepends infinite loops for "while" | |
if (flags.indexOf("g") == -1) { | |
flags += "g"; |
<?php | |
define("CTYPE_PRINT_UNICODE_PATTERN", "~^[\pL\pN\s\"\~". preg_quote("!#$%&'()*+,-./:;<=>?@[\]^_`{|}´") ."]+$~u"); | |
function ctype_print_unicode($input) { | |
return preg_match(CTYPE_PRINT_UNICODE_PATTERN, $input); | |
} | |
print ctype_print_unicode("3 muços?"); // 1 |
// Handles also array params well | |
function parseQueryString(query) { | |
var pars = (query != null ? query : "").replace(/&+/g, "&").split('&'), | |
par, key, val, re = /^([\w]+)\[(.*)\]/i, ra, ks, ki, i = 0, | |
params = {}; | |
while ((par = pars.shift()) && (par = par.split('=', 2))) { | |
key = decodeURIComponent(par[0]); | |
// prevent param value going to be "undefined" as string | |
val = decodeURIComponent(par[1] || "").replace(/\+/g, " "); |
function extract_array_path($path, $value = null, $base = null) { | |
if ($base === null) { | |
static $base = array(); | |
} | |
$exp = explode('.', $path); | |
$tmp =& $base; | |
foreach($exp as $i) { | |
$tmp =& $tmp[$i]; | |
} |
<VirtualHost *:80> | |
ServerName foo.com.local | |
DocumentRoot /var/www/foo.com/public | |
<Directory /var/www/foo.com/public> | |
Options +FollowSymLinks | |
DirectoryIndex index.php | |
AllowOverride all | |
Require all granted | |
$str = <<<EOT | |
Lorem [a href="#"]ipsum[/a] [hr color="red" /] dolor... | |
[style].foo{color:#fff}[/style] | |
EOT; | |
function bbcode_convert($content) { | |
// remove style|script | |
$content = preg_replace( | |
'~(\[(style|sctript)\s?.*\](.*)\[/(\\2)\]|\[(%s)\s?.*/\])~ims', '', $content); |
<?php | |
$url = "https://foo.com//bar/////ii?a=1"; | |
$url = preg_replace("~(?<!:)/+~", "/", $url); | |
print($url); # https://foo.com/bar/ii?a=1 |