Skip to content

Instantly share code, notes, and snippets.

View nikic's full-sized avatar
🌴
On vacation

Nikita Popov nikic

🌴
On vacation
View GitHub Profile
<?php
require './vendor/autoload.php';
// The code samples to parse.
// => bool(false)
$code = '<?php class Foo {public $bar;}';
// => bool(true)
@nikic
nikic / gist:4162505
Created November 28, 2012 16:55
Regex to validate (IPv4) CIDR notation (with capture)
\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(3[0-2]|[1-2]?[0-9])\b
\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.((?1))\.((?1))\.((?1))/(3[0-2]|[1-2]?[0-9])\b
@nikic
nikic / gist:1188670
Created September 2, 2011 14:06 — forked from ircmaxell/gist:1188649
PHP example on variable variables - without needing them
<?php
function bar($a, $b, $c) {
foreach (compact('a', 'b', 'c') as $key => $value) {
$form[$key] = array(
'#type' => 'hidden',
'#value' => $value,
);
}
}