I’ve got another question, although I reckon this one might be a little less mundane. But quick disclaimer, this one’s a little more open-ended, so let me start by saying that I am NOT looking for a complete solution to the greater problem I’m opening here, and I apologise in advance if I’m stretching the limit of acceptable minimums of reference code inclusion. I respect your time, plus I prefer to put the pieces together myself 😛
With that out fo the way, here’s the question:
I’ve set up a PHP function that pulls the text from a Twitter feed and then publishes it as a sort of ‘social media’ sidebar on a website. Trouble is, the links that are included in the Tweets are being reproduced as simple text. Example:
<p>Last night saw the USA win gold in Women's Beach Volleyball---today at 1pm... the
USA WOMEN SOCCER team will go... http://t.co/M7rtaZFC</p>
I’d like to grab that unlinked URL at the end there, wrap it in some friendly ‘a’ tags, and send it on its merry way.
I can figure out just about everything except actually filtering a jQuery return to target ‘http://’ + the rest of the string.
Is this possible using jQuery? Again, I don’t expect anything too in-depth, just looking for someone to point me in the right direction. Thank you for your time!
First Solution using just PHP
I don’t know how you grab the tweets, but I used this PHP-code before and it prints out links right away wrapped in
<a>-tags. So, no need to use JavaScript here:Maybe this helps you.
Edit: Second Solution using JavaScript
If you want an JavaScript-solution, you can go with this:
JavaScript
HTML
This assumes that all
<p>-tags are wrapped within a container with an ID.$(value).text()replaceURLWithHTMLLinksfrom this answer<p>-tag using$(value).html()