Когда производится конкатенация строк с помощью оператора ".", разрешается разрывать..
$sql = "SELECT `id`, `name` FROM `people` "
. "WHERE `name` = 'Susan' "
// закомментировано на время отладки
// . "ORDER BY `name` ASC "
. "ORDER BY `name` DESC LIMIT 5"
;
if( !$(this).val() || $(this).val().replace(/\D/g,'').length < 5) enable = false;
if( !$(this).val() || (
$(this).attr('name') == 'phone'
&& $(this).val().replace(/\D/g,'').length < 5
)) enable = false;
$(document).ready(function(){
setTimeout(function(){
window.scrollTo(0, 0);
}, 1);
});
$(document).ready(function(){
document.location.href='#';
});
class controller_1 {
public function action_1(){
return $template_1->render()
}
}
class controller_2 {
public function action_2(){
$param = (new controller_1)->action_1();
return $template_2->render($param)
}
}
<?php
/*
Класс-маршрутизатор для определения запрашиваемой страницы.
> цепляет классы контроллеров и моделей;
> создает экземпляры контролеров страниц и вызывает действия этих контроллеров.
*/
class Route
{
static function start()
{
// контроллер и действие по умолчанию
$controller_name = 'Main';
$action_name = 'index';
// --------------------------------------------------
$action_params = array();
$routes = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
// --^^------------------------------------------------
// получаем имя контроллера
if ( !empty($routes[1]) )
{
$controller_name = $routes[1];
}
// получаем имя экшена
if ( !empty($routes[2]) )
{
$action_name = $routes[2];
}
// --------------------------------------------------
if (count($routes)>2) {
$action_params = array_slice($routes, 2);
}
// --^^------------------------------------------------
// добавляем префиксы
$model_name = 'model_'.$controller_name;
$controller_name = 'controller_'.$controller_name;
$action_name = 'action_'.$action_name;
/*
echo "Model: $model_name <br>";
echo "Controller: $controller_name <br>";
echo "Action: $action_name <br>";
*/
// подцепляем файл с классом модели (файла модели может и не быть)
$model_file = strtolower($model_name).'.php';
$model_path = "application/models/".$model_file;
if(file_exists($model_path))
{
include "application/models/".$model_file;
}
// подцепляем файл с классом контроллера
$controller_file = strtolower($controller_name).'.php';
$controller_path = "application/controllers/".$controller_file;
if(file_exists($controller_path))
{
include "application/controllers/".$controller_file;
}
else
{
/*
правильно было бы кинуть здесь исключение,
но для упрощения сразу сделаем редирект на страницу 404
*/
Route::ErrorPage404();
}
// создаем контроллер
$controller = new $controller_name;
$action = $action_name;
if(method_exists($controller, $action))
{
// вызываем действие контроллера
// --------------------------------------------------
call_user_func_array(array($controller, $action), $action_params)
// --^^------------------------------------------------
}
else
{
// здесь также разумнее было бы кинуть исключение
Route::ErrorPage404();
}
}
function ErrorPage404()
{
$host = 'http://'.$_SERVER['HTTP_HOST'].'/';
header('HTTP/1.1 404 Not Found');
header("Status: 404 Not Found");
header('Location:'.$host.'404');
}
}
class controller {
public function action($param_1, $param_2,...,$param_n) {
}
}
$text = '
<a href="http://test1.ru">Test 1</a> text
<a href="http://test1.ru">Test 2</a> text
';
$text = preg_replace_callback('~http://~', function($match) {
return $match[0] . 'www.';
}, $text);
echo $text;
$regexp = "/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i";
$string = preg_replace_callback($regexp, function($match){
return $match[1] . "http://" . shortUrl($match[2]);
}, $string);
menu_category
~~~~~~~
id
name
order
menu_items
~~~~~~~~~~~
id
menu_category_id
name
url
order
SELECT
`c`.`id` as `id`,
`c`.`name` as `name`,
`i`.`id` as `item_id`,
`i`.`name` as `item_name`,
`i`.`url` as `item_url`
FROM `menu_category` as `c`
LEFT JOIN `menu_items` as `i` ON `i`.`menu_category_id`=`c`.`id`
ORDER BY `c`.`order`, `i`.`order`
$menu = [];
foreach ($results as $res) {
$menu[$res['id']]['name'] = $res['name'];
$menu[$res['id']]['items'][] = [
'name' => $res['item_name'],
'url' => $res['item_url'],
]
}
[1]=>[
'name' => 'Категория 1',
'items' => [
['name'=>'Ссылка 11', 'url'=>'http://site11.ru'],
['name'=>'Ссылка 12', 'url'=>'http://site12.ru'],
]
],
[2]=>[
'name' => 'Категория 2',
'items' => [
['name'=>'Ссылка 21', 'url'=>'http://site21.ru'],
['name'=>'Ссылка 22', 'url'=>'http://site22.ru'],
]
],
echo '<ul>';
foreach($menu as $catId=>$cat) {
echo '<li>'.$cat['name'];
if (isset($cat['items'])) {
echo '<ul>';
foreach($cat['items'] as $item) {
echo '<li><a href="'.$item['url'].'">'.$item['name'].'</a></li>';
}
echo '</ul>';
}
echo '</li>';
}
echo '</ul>';
$start = new DateTime('01.08.2014');
$end = new DateTime('30.08.2015 23:59');
$interval = new DateInterval('P1D');
$dateRange = new DatePeriod($start, $interval, $end);
$weekNumber = 1;
$weeks = array();
foreach ($dateRange as $date) {
$weeks[$weekNumber][] = $date->format('Y-m-d');
if ($date->format('w') == 0) {
$weekNumber++;
}
}
echo '<pre>';
print_r($weeks);
echo '</pre>';