Hey, this is my first post here, so greetings lol. Back to the topic, Is it possible to make a text box that can put the text into html code and if so how? Sort of like the box you type your post's with on forums or blogs.

Recommended Answers

This is normally done using MySQL or MongoDB to save the data and PHP to display it.
You can use flat files but then you loose a lot of the power you can get from databases like MySQL or MongoDB
A simple, flat-file example would be

<?php …
Jump to Post

All 2 Replies

This is normally done using MySQL or MongoDB to save the data and PHP to display it.
You can use flat files but then you loose a lot of the power you can get from databases like MySQL or MongoDB
A simple, flat-file example would be

<?php
//Output whatever is stored in the file
@echo file_get_contents('./storage');
?>
<!--Make a form for input-->
<form method="POST" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<input type="text" name="input" /><input type="submit" />
</form>

<?php
//If the form has been submitted
if ( isset($_POST) ) {
    //Open the file for writing (w)
    $f = fopen('./storage', 'w');
    //Write the string
    fwrite($f,$_POST['input']);
    //Close the file
    fclose($f);
}
?>

(Not tested)
That code is very insecure and using files is very inefficient as opposed to databases.
If you check out http://tizag.com/ they have good tutorials on both PHP files and MySQL with PHP.
-Sam

Member Avatar

You have two main options. Either use a plain textbox and use BBCode or use a WYSIWYG editor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.