Only replace own website url in text with HTML links?
-
When user post a comment, i strip all the html tags in the comment before insert into my database because i do not want them to post external links(SPAM) in the comment. But i only want to strip external links, i want to display my own website URL as normal clickable links. How to detect the URL is my own website's URL and make it clickable as usual? Example in the comment: Blah... blah... blah... http://my_website_url.com Blah... blah... blah... Blah... blah... blah... Blah... blah... blah... Blah... blah... blah... Blah... blah... blah...http://external_links.com Blah... blah... blah... Blah... blah... blah... As above example, i want ONLY http://my_website_url.com become clickable link before insert into my database. (http://my_website_url.com to < a href="http://my_website_url.com" ><http://my_website_url.com< /a > ) Also, not only detect the main URL:http://my_website_url.com, but also: -http://www.my_website_url.com -www.my_website_url.com -my_website_url.com -http://my_website_url.com/blah/blah/blah -www.my_website_url.com/blah/blah/blah -my_website_url.com/blah/blah/blah or any URLs that from my website:http://www.my_website_url.com/xxx/xxx/xxx/xxx If could, please post exactly php codes to let me copy and paste into my file because i have little knowledge with php only. Thanks guys. :)
-
Answer:
You'ld probably want to use a regular expression (regex) to determine if it is an internal link. Google php, regular expressions to figure out how to use them, shouldn't be too complex :)
rp at Yahoo! Answers Visit the source
Related Q & A:
- How to add links on the fly in a website?Best solution by Yahoo! Answers
- Is tv links an illegal website?Best solution by Yahoo! Answers
- How to get more links to my website?Best solution by Yahoo! Answers
- What is the best way to get back links to a website?Best solution by Yahoo! Answers
- How do you the Hide bottom links and copyright text on a myspace 2.0 layout?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.