Jump to content

Archived

This topic is now archived and is closed to further replies.

webdogjcn

converting form data

Recommended Posts

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>

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
When you want to display the text use the nl2br() function which will insert "<br ?>" tags before each newline character.
[code]<?php echo nl2br($message) ?>[/code]

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.