V
V
Vasya Surname2017-08-15 15:21:32
PHP
Vasya Surname, 2017-08-15 15:21:32

How to wrap a hashtag in a link?

How to wrap a hashtag in a link?
Something like this
#sky #sea
in the code should turn out

<a href="tag/небо">#небо</a> <a href="tag/море">#море</a>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene Mosyukov, 2017-08-15
@bazilio2010

$string = '#небо #море';
echo preg_replace('/#([a-zа-я0-9]+)/ui', '<a href="tag/$1">#$1</a>', $string);

A
Alexander Aksentiev, 2017-08-15
@Sanasol

https://www.google.ru/search?q=php+hashtag+to+link

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question