Forum categories

Появляется amp; после & в ссылке. Как исправить?

Не косается конкретно этой сборки, маленький PHP-фикс в целом для Cotonti


webitproff
webitproff • 2025-01-05 11:56 #1

 

Бывает, что в уже в клиентской части страницы, в HTML-коде, в ссылке вместо «&» получаем «&».

Это потому, что со знака «&» (амперсанд) начинаются комбинации символов (HTML-коды), чтобы корректно отображать определенные знаки на веб-страницах.
например:

© - © - копирайт
$ - $ - знак доллара
😀 - 😀 - Улыбающееся лицо.

Например, в каком либо плагине, в php-файлах нужно получить ссылку и передать её tpl-файлы, чтобы уже в нужном месте, эту гипертекстовую ссылку вывести или подключить.

В .tpl
создаем тег {MY_TAG}, для размещения его в шаблоне.

В .php

$my_url = str_replace('&', '&', cot_url('forums', "m=posts&id=" . $p));
....
$mskin = cot_tplfile([
	'zakaz', 
	'posts', 
	Cot::$structure['zakaz'][$s]['tpl']
]);
$t = new XTemplate($mskin);

$arrayMyTags = [
	...
	'MY_TAG' => Cot::$cfg['mainurl'] . '/' . $my_url,
	....
];

....

$t->assign($arrayMyTags);

......

$t->parse('MAIN');


str_replace - в данном случае, - это функция, которая возвращает строку,

где ищем первый аргумент '&'

и заменяем на второй аргумент '&'

в третьем аргументе - тело ссылки cot_url('forums', "m=posts&id=" . $p)

 

This post was edited by webitproff (2025-01-06 08:00, 1 year ago)
🗿

🧙‍♂️ Well met, good traveler! Fate has guided your steps to our humble realm. Here, wise sages and masters of the coding craft ⚒️📜 gather to unravel the mysteries of the code ✨⚙️, share their knowledge, and add new chapters to our chronicles.
⬅️ To the left lie ancient scrolls 📚 filled with forgotten wisdom. ⬆️ Straight ahead, friendly folk offer counsel 💬 to those in need. ➡️ To the right, you may become a chronicler ✍️ yourself, sharing your craft and leaving words of wisdom for those yet to come.
📝 Delay no longer—tell us the name by which you are known, complete the rite of registration 🛡️, and join our fellowship!
🏰 Our brotherhood holds no secret initiation, yet many halls remain closed to wandering guests, for some knowledge 💎 is reserved for those who choose to walk this path beside us.