Answer the question
In order to leave comments, you need to log in
How to convert words to hash tags in Yii2?
When you enter question tags on this site, you get a set of words, which is then converted into links, or so-called hash tags.
Let's say I put these words on a website page:
<div>
<?php foreach ($janre as $tab) { ?>
<?=$tab->id_j?>
<?php } ?>
</div>
<div>фантастика ужасы</div>
var y;
var message = new Array();
message[1] = 'фантастика';
message[2] = 'ужасы';
//Выведем все элементы массива и заменим на ссылки
for (y in message) {
document.body.innerHTML = document.body.innerHTML.replace(message[y], '<a href="https://vk.com/feed?q=' + message[y] + '§ion=search" target="_blank">#' + message[y] + '</a> ');
}
<div>
<a href="https://vk.com/feed?q=фантастика§ion=search" target="_blank">#фантастика</a>
<a href="https://vk.com/feed?q=ужасы§ion=search" target="_blank">#ужасы</a>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question