Page 1 of 1

Showing formatted text from forms

Posted: Sun Feb 22, 2004 8:58 am
by hurrajag
Is there any way to make, using forms (textarea), text show like you type it, eg. a linebreak is shown like <br>?
I tried using <pre> but then it didn't use the space it had in the table, and it didn't break the line when crossing an image, which I would like it to do, is there any way to do this? Also, in the text, can you make some kind of link-sign that automatically changes it to <a href="$link">$linktext</a>? Like you can often write something like [link adress]linktext[/link]?

Thank you.
// HurraJag

Posted: Sun Feb 22, 2004 9:09 am
by Bill H
Try nl2br($text);

Posted: Sun Feb 22, 2004 10:24 am
by qads

Code: Select all

<?php
function parseurls($data){ 
   $data = " ".$data; 

   $data = eregi_replace('([[]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', 
   '\\1<a href="http://\\2" target="_blank">\\2</a>', $data); 

   $data = eregi_replace('([[]()[{}])(http://[-a-zA-Z0-9@:%_\+.~#?&//=]+)', 
  '\\1<a href="\\2" target="_blank">\\2</a>', $data); 

   return trim($data); 
}
?>
use: $text = parseurls($text);

it will turn any url to a link, no need forurl.