I am using Twitter-API to get tweets in JSON. Now I would like to style my tweets like making hashtags with other color than text.
I don't know how to style text which start with #.
Now I get JSON like this:
Array
(
[0] => Array
(
[created_at] => Fri Dec 21 08:39:05 +0000 2018]
[id] => 1076034307246960640
[id_str] => 1076034307246960640
[text] => @em_finland'in #EuroopanSuunta-podcastissa tällä kertaa jutustelemassa meikäläinen ja MEP @HennaVirkkunen. Aiheina…
)
)
I want to change the color of hashtags (tag and text - #EuroopanSuunta in the example ) but I don't know how to get all of them within the text.
EDIT: After @Yaakov Ainspan comment I made this in jQuery:
var oldHtml = $(".twitter_text1").html();
var newHtml = oldHtml.replace(new RegExp(/(\W(\#[a-zA-Z]+\b))/g), "<span class='highlight'>$1</span>");
And that's work. Closed.
Comments
Post a Comment