$a = 'abc';
echo $a{0}; // Output: a
echo $a{1}; // Output: b
$str = 'abcd';
if (isset($str{3})) {
echo "enough";
}
$pattern = '/<a href=\".*\">.*<\/a>/'; // ugly!
$pattern = '#<a href=".*">.*</a>#'; // wonderful!
# Usually
$arr = ['tom', 'jerry', 'peter'];
if (in_array($v, $arr)) {
return true;
} else {
return false;
}
# Better
$arr = ['tom', 'jerry', 'peter'];
$arr_handled = array_flip($arr);
if (isset($arr_handled[$v])) {
return true;
} else {
return false;
}
$start = 'a';
for ($n = 0;$n < 26;$n++) {
echo $start;
$start++;
}
In command line mode in PHP, max_execution_time
is 0 as default, whatever the value in php.ini
.
You can set time limit with two methods below:
set_time_limit(3)
ini_set('max_execution_time', 1)
Caution:
Both set_time_limit(...)
and ini_set('max_execution_time',...);
won't count the time cost of sleep
,file_get_contents
,shell_exec
,mysql_query
etc.
Use for(;;);
is a good idea.
$sNoEndOfLine = str_replace(PHP_EOL, "", $sString);
strtotime(date('Y-m') . '+1 month');