Jump to content


Photo

converting form data


  • Please log in to reply
3 replies to this topic

#1 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 06 June 2006 - 09:59 PM

okay so I have a fast reply form and a link that lets you insert emoticons. well i have everything working where a pop-up appears and the emoticon text is displayed like ";sad;" (replace ; with :) and now I want to convert all instances (when they submit the form) of ;sad; with <image src="sad.gif" alt=sad>

#2 markduce

markduce
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 06 June 2006 - 10:33 PM

OK, just use the str_replace function (string replace) as follows:

<?
$message=$_POST['message'];
// OR WHATEVER YOUR MESSAGE VARIABLE IS
$message=str_replace(';sad;', '<image src="sad.gif" alt=sad>', $message);
?>

Hope that helps

Mark

#3 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 07 June 2006 - 04:24 PM

Okay, thanks for the help. But one more question, what about convereting user entered line breaks to <br>?
Because when someone presses enter in a textarea it will just recognize it as a space not a line break.

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 07 June 2006 - 05:32 PM

When you want to display the text use the nl2br() function which will insert "<br ?>" tags before each newline character.
<?php echo nl2br($message) ?>

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users