HooLIGUN 4 Posted September 3, 2021 Report Share Posted September 3, 2021 Добрый день. Подскажите, как экранировать всякие символы в модуле Pages ? Например есть $str = "{{qwert{{}}"; и при выводе в блоке <? echo $str; ?> страница выдает ошибку [[Block blockkey is throwing an error]] Пробовал quotemeta и htmlspecialchars - не помогает Раньше пользовался mysql_real_escape_string, но этот метод не актуален Обратиться Quote Link to comment Share on other sites More sharing options...
Кирилл 170 Posted September 3, 2021 Report Share Posted September 3, 2021 Привет. {{ try{ }} {{ } catch( \Exception $ex ){ }} {{ } }} В php это: try{ } catch( \Exception $ex ){ } Обратиться Quote Link to comment Share on other sites More sharing options...
HooLIGUN 4 Posted September 3, 2021 Author Report Share Posted September 3, 2021 Кирилл Не работает, и это немного не то Мне нужно, чтобы строка выводилась с любыми символами. Может в IPS есть функция, которая обрабатывает, например, кривые ники юзеров? Обратиться Quote Link to comment Share on other sites More sharing options...
Кирилл 170 Posted September 7, 2021 Report Share Posted September 7, 2021 HooLIGUN для обработки чистого php в шаблонах, используется конструкция {expression=''}; Обратиться Quote Link to comment Share on other sites More sharing options...
HooLIGUN 4 Posted November 25, 2021 Author Report Share Posted November 25, 2021 (edited) К сожалению, решения так и не нашел. Прилагаю полностью проблемный код, который можно протестировать. Есть отдельная база, в ней таблица users со столбцами id и nick Создал блок с кодом и вставил в новую страницу (Приложение Pages) $connection = \IPS\Db::i( 'external', array( 'sql_host' => 'localhost', 'sql_user' => 'user', 'sql_pass' => 'pass', 'sql_database' => 'db', 'sql_port' => 3306, # 'sql_socket' => '/var/lib/mysql.sock', 'sql_utf8mb4' => true, ) ); try { $data = $connection->select( '*', 'users','id = 2' )->first(); } catch( \UnderflowException $e ) { \IPS\Output::i()->error( ' ID не найден', '404', 404, '' ); } echo $data['nick']; Так вот, если выбирать из базы id = 1 и id = 2 , то будет ошибка Если выбрать id = 3 (нормальный ник, без $ и {{}}) то всё ок, выводит ник. Edited November 25, 2021 by HooLIGUN Обратиться Quote Link to comment Share on other sites More sharing options...
Кирилл 170 Posted November 25, 2021 Report Share Posted November 25, 2021 HooLIGUN данная ошибка должна быть записана в лог ошибок. Обратиться Quote Link to comment Share on other sites More sharing options...
HooLIGUN 4 Posted November 25, 2021 Author Report Share Posted November 25, 2021 7 минут назад, Кирилл сказал: HooLIGUN данная ошибка должна быть записана в лог ошибок. Ругается на символы {{}} {$} , воспринимаются как код в шаблоне Обратиться Quote Link to comment Share on other sites More sharing options...
HooLIGUN 4 Posted November 25, 2021 Author Report Share Posted November 25, 2021 30 минут назад, Кирилл сказал: HooLIGUN данная ошибка должна быть записана в лог ошибок. При выводе `id` = 1 такая ошибка При выводе `id` = 2 такая Обратиться Quote Link to comment Share on other sites More sharing options...
Павел 139 Posted November 25, 2021 Report Share Posted November 25, 2021 Запрос должен выглядеть так: $data = $connection->select( '*', 'users', array( 'id=?', 2 ) )->first(); 1 Обратиться Quote Link to comment Share on other sites More sharing options...
HooLIGUN 4 Posted November 25, 2021 Author Report Share Posted November 25, 2021 19 минут назад, Павел сказал: Запрос должен выглядеть так: $data = $connection->select( '*', 'users', array( 'id=?', 2 ) )->first(); Спасибо за дополнение. Набросал это на скорую руку, но так и так запрос выполняется. Не работает сам результат, в котором есть символы вывода\обработки php в шаблонах {{$}} Обратиться Quote Link to comment Share on other sites More sharing options...
Кирилл 170 Posted November 25, 2021 Report Share Posted November 25, 2021 {{ try{ }} {{$select = \IPS\Db::i()->select( 'nick', 'users', array( 'id=?', 2 ) )->first();}} {{ } catch( \Exception $ex ){ }} {{ } }} {$select} Обратиться Quote Link to comment Share on other sites More sharing options...
HooLIGUN 4 Posted November 25, 2021 Author Report Share Posted November 25, 2021 24 минуты назад, Кирилл сказал: {{ try{ }} {{$select = \IPS\Db::i()->select( 'nick', 'users', array( 'id=?', 2 ) )->first();}} {{ } catch( \Exception $ex ){ }} {{ } }} {$select} Я использую "чистый" php в блоке приложения страницы. А этот пример ведь для использования в шаблонах. Обратиться Quote Link to comment Share on other sites More sharing options...
Кирилл 170 Posted November 25, 2021 Report Share Posted November 25, 2021 HooLIGUN Я такой режим не использую совсем, но что-то мне подсказывает, что это особенность такого типа блоков в IPS. Обратиться Quote Link to comment Share on other sites More sharing options...
HooLIGUN 4 Posted November 26, 2021 Author Report Share Posted November 26, 2021 Пришлось использовать костыли.. function ips_fixname ($name) { $name = str_replace('{', '', $name); $name = str_replace('}', '', $name); $name = str_replace('$', '', $name); return $name; } Если вдруг у кого будут идеи лучше, прошу поделиться, буду рад услышать 1 Обратиться Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.