pioneerx01 Posted February 16, 2011 Share Posted February 16, 2011 Lets say that I want to make a certain word (or words) on a page a link. How would I make it a link without having to code in a link. Some site have adds on certain words; one day and not the next day. I am looking for similar feature, but less intrusive. No pop-up, just a link. Quote Link to comment Share on other sites More sharing options...
lastkarrde Posted February 16, 2011 Share Posted February 16, 2011 You could use str_replace on your content before it is output onto the browser. Sort of like: $output = str_replace(' Chicken ', ' <a href="/tag/Chicken">Chicken</a> ', $content); echo $output; Quote Link to comment Share on other sites More sharing options...
pioneerx01 Posted February 16, 2011 Author Share Posted February 16, 2011 I can not seem to be able to get it to work. Where exactly should I place this code. I tried both in header and body, but none works. I am new to PHP, but what exactly defines "$content" Would I have to recode my paragraphs as $content = paragraph Chicken paragraph; echo "$content"; Quote Link to comment Share on other sites More sharing options...
lastkarrde Posted February 16, 2011 Share Posted February 16, 2011 Im assuming $content is the content (text you want auto links generated from) before it is output on the screen. However I guess your website isn't set up that way. Doesn't matter, because you can do it in Javascript anyway ^^ . Have a look at http://stackoverflow.com/questions/1774269/auto-link-specific-words-and-phrases and http://psoug.org/snippet/Javascript-Auto-Link-words_113.htm Quote Link to comment Share on other sites More sharing options...
pioneerx01 Posted February 18, 2011 Author Share Posted February 18, 2011 Hi, I have looked at both links (as thoroughly as I know how) but I can not get either working. I know nothing about Javascript, which is probably why I can not get it to work. <html> <head> <script type="text/javascript"> FUNCTION linkWord(obj){ FOR(i IN obj){ VAR x = document.body.innerHTML; VAR linkStart = '<a href="'+obj[i]+'">'; VAR linkEnd = '</a>'; VAR reg = NEW RegExp ('\\b' + i + '\\b','g'); x = x.replace(reg, linkStart + i + linkEnd); document.body.innerHTML = x; } } </script> </head> <body> <p>Check out these cables!</p> </body> </html> Where do I place: 'cables':'http://www.google.com', to make cables as hyperlink to a site (Google in this example)? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.