JasperHope Posted April 18, 2010 Share Posted April 18, 2010 Hey guys. I'm creating a textbox which saves its content into a .txt. Then the HTML will read it and place it onto a div. This is the code I'm using for the write part: <? $content = $_POST['content']; $file = "../blog/file.txt"; $Saved_File = fopen($file, 'w'); fwrite($Saved_File, $content); fclose($file); ?> It works great! However, it saves it raw. Meaning no HTML tags. For example: Test Test Would want to be saved as Test<br/> Test<br/> And so on. So is it possible to insert these tags automatically? I have a basic BBCode PHP mod type thing that will convert BBCode tags into HTML. Here is the code for that: <?php // A simple FAST parser to convert BBCode to HTML // Trade-in more restrictive grammar for speed and simplicty // // Syntax Sample: // -------------- // [img=http://elouai.com/images/star.gif] // [url=http://"http://elouai.com"]eLouai[/url] // [mail="[email protected]"]Webmaster[/mail] // [size="25"]HUGE[/size] // [color="red"]RED[/color] // [b]bold[/b] // [i]italic[/i] // [u]underline[/u] // [list][*]item[*]item[*]item[/list] // [code]value="123"; // John said yadda yadda yadda // // Usage: // ------ // <?php include 'bb2html.php'; ?> // <?php $htmltext = bb2html($bbtext); ?> // // (please do not remove credit) // author: Louai Munajim // website: http://elouai.com // date: 2004/Apr/18 function bb2html($text) { $bbcode = array("<", ">", " ", " ", " ", "", "", "", "", "", "", "", '", "", '", "[mail=\"", "[/mail]", " ", " ", " ", " ", '"]'); $htmlcode = array("<", ">", "<ul>", "<li>", "</ul>", "<img src=\"", "\">", "<b>", "</b>", "<u>", "</u>", "<i>", "</i>", "<span style=\"color:", "</span>", "<span style=\"font-size:", "</span>", '<a href="', "</a>", "<a href=\"mailto:", "</a>", "<code>", "</code>", "<table width=100% bgcolor=lightgray><tr><td bgcolor=white>", "</td></tr></table>", '">'); $newtext = str_replace($bbcode, $htmlcode, $text); $newtext = nl2br($newtext);//second pass return $newtext; } ?>[/code] Link to comment https://forums.phpfreaks.com/topic/198902-php-save-to-txt-file/ Share on other sites More sharing options...
litebearer Posted April 18, 2010 Share Posted April 18, 2010 have you considered rte... http://www.kevinroth.com/rte/demo.php Link to comment https://forums.phpfreaks.com/topic/198902-php-save-to-txt-file/#findComment-1044063 Share on other sites More sharing options...
JasperHope Posted April 18, 2010 Author Share Posted April 18, 2010 have you considered rte... http://www.kevinroth.com/rte/demo.php Oh wow that is perfect. Thank you! Link to comment https://forums.phpfreaks.com/topic/198902-php-save-to-txt-file/#findComment-1044064 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.