I
I
Igor Vasiliev2016-09-28 04:41:40
Yii
Igor Vasiliev, 2016-09-28 04:41:40

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>

I got a set of words:
<div>фантастика ужасы</div>
I wrote javascript that made these words links (hash tags)
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] + '&section=search" target="_blank">#' + message[y] + '</a> ');
}

You get something like:
<div>
<a href="https://vk.com/feed?q=фантастика&section=search" target="_blank">#фантастика</a> 
<a href="https://vk.com/feed?q=ужасы&section=search" target="_blank">#ужасы</a>
</div>

-------------------------------------------------- --------------------
QUESTION:
How to implement all this without crutches in Yii2 with minimal code, without installing someone's development? I have a script, a database is connected, tags are entered and added to the input, all I need is a Yii implementation of hash tags, no matter how many of them the user adds.
--
Thank you in advance for your response, and refraining from reproaches and moralizing.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-09-28
@Isolution666

Good afternoon.
Here is a webinar, there is how to organize tags, maybe it will help you in solving the problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question