DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   PHP - How to Enable Hyperlinks ONLY in Posts (http://www.daniweb.com/forums/thread80959.html)

123cc Jun 14th, 2007 1:21 pm
PHP - How to Enable Hyperlinks ONLY in Posts
 
Hi,

I am using a PHP form and I would like to have the ability to convert any emails and URLs that are in the post to automatically have a hyperlink.

I don't want to enable any other html tag other than the hyperlink in my posts and I am not sure how this can be accomplished.

Thanks in advance for your response.

--

Rhyan Jun 15th, 2007 3:40 am
Re: PHP - How to Enable Hyperlinks ONLY in Posts
 
Hmmmm, well, using php, the first thing that comes up to my mind is to do something like this, however, it may turn out to be reaaallly slow with large posts. However, you can try it.

1. After submit, the content of the form gets exploded into an array.
2. Each value of this array is then checked for strings http://, or www., or @
3. If one of the following is found, you have to store the value again in the array with some extra data, which is - if it is an url, it should be something like <a href="value goes here">Value goes here</a>, or if it is an e-mail, it will be <a href="mailto:your value goes here">Your value here</a>.
4. Implode the array into a variable in the same order, in order to maintain text structure.
5. Write the post to a database, or do whatever you want with it.

Maybe the other guys here will figure out a smarter way, as it seems to me this is not the best solution.

Cheers.

Fungus1487 Jun 15th, 2007 8:27 pm
Re: PHP - How to Enable Hyperlinks ONLY in Posts
 
sounds sensible to me. look into using 'oreg_replace' as you can specify regular expressions to convert the string http://uk2.php.net/manual/en/function.preg-replace.php

cscgal Jun 17th, 2007 3:17 am
Re: PHP - How to Enable Hyperlinks ONLY in Posts
 
Yeah, it's preg_replace, not oreg_replace. Also read up about regex (regular expressions).


All times are GMT -4. The time now is 11:17 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC