Showing formatted text from forms

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hurrajag
Forum Newbie
Posts: 5
Joined: Wed Feb 04, 2004 10:32 am

Showing formatted text from forms

Post 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
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

Try nl2br($text);
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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.
Post Reply