M
M
mountain1232015-12-10 14:10:35
PHP
mountain123, 2015-12-10 14:10:35

How to convert a hashtag into a link?

I pull out the news from the contact using wall.get. I get the text of the news with hashtags. Hashtags come as plain text. With this function, I replace hashtags with links, but only English hashtags change. What regular expression is needed to select Cyrillic

function hashtag($text){
    $pattern = "/\#(\w+)/";
    $text= preg_replace($pattern, '<a href="http://vk.com/feed?q=%23$1&section=search" target="_blank">#$1</a>',$text);
    echo $text;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey, 2015-12-10
@mountain123

first try
to make your expression ignore case and work with multibyte characters

E
Evgeny Svirsky, 2015-12-10
@e_svirsky

/\#[^A-Za-zА-Яа-яЁё]+/u
u - to work with UTF-8

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question