Topic: how to add hashtag?

here my script

    $pattern[] = '#(#(\w+))#ms'; 
    $replace[] = '<a href=\"http://search.twitter.com/search?q=$matches[2]\" target=\"_blank\">#$matches[1]</a>'; 

but didnt work, why ?
i use punbb 144 n php 5.6

please ur help punbb

sorry my BAD english T___T
Have a nice day >.<
(^____^)v

Re: how to add hashtag?

$pattern[] = '%(?<=^|\s)(?:#(\w+))(?=\s|$)%u'; 
$replace[] = '<a href=\"http://search.twitter.com/search?q=$matches[1]\" target=\"_blank\">#$matches[1]</a>';
 

Test https://regex101.com/r/hV1gP3/1

ForkBB
I speak only Russian  :P

3 (edited by kudataz 2015-12-04 21:15)

Re: how to add hashtag?

Visman wrote:
$pattern[] = '%(?<=^|\s)(?:#(\w+))(?=\s|$)%u'; 
$replace[] = '<a href=\"http://search.twitter.com/search?q=$matches[1]\" target=\"_blank\">#$matches[1]</a>';
 

Test https://regex101.com/r/hV1gP3/1

this code work if any link on post,
if dont have link the hashtags wont be able sad
please ur help

i've 2 questions through script before:
- why use % insted # ?
- why use u instead ms ?

please give me explain for learn it big_smile

sorry my BAD english T___T
Have a nice day >.<
(^____^)v

Re: how to add hashtag?

>- why use % insted # ?
For #

$pattern[] = '#(?<=^|\s)(?:\#(\w+))(?=\s|$)#u'; 

one symbol more.

>- why use u instead ms ?
u -> Unicode
In this regular expression modifiers m and s don't make sense as search goes only on letters and figures.

this code work if any link on post,
if dont have link the hashtags wont be able sad
please ur help

Show links to messages where the code works incorrectly.

ForkBB
I speak only Russian  :P

Re: how to add hashtag?

image tell more..
http://s7.postimg.org/ddwj17w3f/2015_12_06_054940.png
there is no eror log generate

sorry my BAD english T___T
Have a nice day >.<
(^____^)v

Re: how to add hashtag?

bb-codes work only if

    if ($forum_config['p_message_bbcode'] == '1' && strpos($text, '[') !== false && strpos($text, ']') !== false)

Use ps_parse_message_bbcode hook

$text = preg_replace('#(?<=^|\s)(?:\#(\w+))(?=\s|$)#u', '<a href="http://search.twitter.com/search?q=$1" target="_blank">#$1</a>', $text);
ForkBB
I speak only Russian  :P

Re: how to add hashtag?

Gretas work fine..
the best place ps_parse_message_bbcode without eror
thxx a loot guru Mr.Visman
thxx u punbb
big_smile

sorry my BAD english T___T
Have a nice day >.<
(^____^)v