ha***********@g mail.com schreef:
Hi,
I have a blog which people often include a link in their comment.
Can anyone point me to a script or demonstrate how I can automatically
surround the text links with an anchor when the page is rendered? As
an example, here is a typical comment:
Hi! Great pics - have you seen this one? http://warehouse.carlh.com/comic/comic_062.php
...but I want the html rendered to be this:
Hi! Great pics - have you seen this one? <a href="http://
warehouse.carlh .com/comic/comic_062.php">http://warehouse.carlh.com/
comic/comic_062.php</a>
I should also point out I only want this to happen in the comments
area, which is contained in a div called 'comments'. Either that, or
the script will need to ignore existing anchors (like in the original
article etc)
Thanks in advance.
Hi,
Well, you described yourself what you need.
For starters: I think it the easiest to process a fresh posting so it
contains the desired HTML instead of parsing the content every time you
display it.
In that case you also don't need to find the <div id="comments">
because, I expect, you add that when displaying the page.
Right?
So, for a certain fresh posting:
1) Find anything that starts with http://
2) Find the next space.
The piece of text inbetween can be a valid hyperlink.
Of course, it can also be nonsense.
Do you want to check this too?
Next step is, possibly, to check if the poster did provide the <a
href=""already.
Do you accept partial HTML in your postings? Like:
<span style="">some text</span>
or
<a href="whatever" >my link</a>
This can quickly become complex, but since you didn't provide the
details on WHAT is posted, it is hard to help you with good advise.
So, bottomline, do you accept html in your postings?
If not, I think you can easily add the hyperlinks.
This can be done with standard stringfunctions , or with a regex.
If you do, and accept partial html, we enter a swamp (I expect).
Regards,
Erwin Moller