• We just launched and are currently in beta. Join us as we build and grow the community.

Facebook Hash Tag and Clickable Link Tutorial

hghgh

Mockery Master
H Rep
0
0
0
Rep
0
H Vouches
0
0
0
Vouches
0
Posts
89
Likes
43
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
Today is another fresh tutorial for your social media networking site. after this tutorial you will be able to enable #hashtags and clickable link into your media networks as most social media do. I used this script on my Jquery instant messager app.

Function for hashtag
The script below contain function for clickable link and hashtag, copy and run the code...

  1. <?php
  2. //convert hashtags
  3. function

    gethashtags(

    $text

    )
  4. {
  5. //Match the hashtags
  6. preg_match_all

    (

    '/(^|[^a-z0-9_])#([a-z0-9_]+)/i'

    ,

    $text

    ,

    $matchedHashtags

    )

    ;
  7. $hashtag

    =

    ''

    ;
  8. // For each hashtag, strip all characters but alpha numeric
  9. if

    (

    !

    empty

    (

    $matchedHashtags

    [

    0

    ]

    )

    )

    {
  10. foreach

    (

    $matchedHashtags

    [

    0

    ]

    as

    $match

    )

    {
  11. $hashtag

    .=

    preg_replace

    (

    "/[^a-z0-9]+/i"

    ,

    ""

    ,

    $match

    )

    .

    ','

    ;
  12. }
  13. }
  14. //to remove last comma in a string
  15. return

    rtrim

    (

    $hashtag

    ,

    ','

    )

    ;
  16. }

  17. //convert text to clickable links
  18. function

    convert_clickable_links(

    $message

    )
  19. {
  20. $parsedMessage

    =

    preg_replace

    (

    array

    (

    '/(?i)\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“â€â€˜â€™]))/'

    ,

    '/(^|[^a-z0-9_])@([a-z0-9_]+)/i'

    ,

    '/(^|[^a-z0-9_])#([a-z0-9_]+)/i'

    )

    ,

    array

    (

    '<a href="$1" target="_blank">$1</a>'

    ,

    '$1<a href="">@$2</a>'

    ,

    '$1<a target="_blank" href="http://codexpresslab.blogspot.com.ng/search?q=$2">#$2</a>'

    )

    ,

    $message

    )

    ;
  21. return

    $parsedMessage

    ;
  22. }
  23. $txt

    =

    "hello man this is #hashtags tutorial. http://codexpresslab.blogspot.com/"

    ;
  24. echo

    convert_clickable_links(

    $txt

    )

    ;
  25. ?>

Conclusion:
I hope you successfully add this function to your site. If you are facing any difficulty then let me know via comments. Keep sharing this post with your friends so that they can also enjoy the post till then Happy Coding!

 

452,292

323,526

323,535

Top