rickmick Posted August 16, 2011 Share Posted August 16, 2011 I have a code that will onclick, change a smiley face image to text in the textarea. When I click submit on the text area all it does is display the same text on my comment, not an image of smiley face. Here is the function. function insertSmiley(smiley) { var currentText = document.getElementById("comment"); var smileyWithPadding = " " + smiley + " "; currentText.value += smileyWithPadding; currentText.focus(); } And then the html. <img src="{SITE_URL}/smile/smile.gif" onclick="insertSmiley('')" /> <img src="{SITE_URL}/smile/beam.gif" onclick="insertSmiley(':-)')" /> <img src="{SITE_URL}/smile/bounce.gif" onClick="insertSmiley(':=(')" /> <img src="{SITE_URL}/smile/boxer.gif" onclick="insertSmiley('=')" /> The code above works great to enter text into my textarea, but i also want it to convert to a image when I hit submit. I have read articles for about 3 days with no luck. The answer might be there but I am to dumb to know it. Thank you [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/244921-how-to-change-smiley-text-to-image-in-textarea/ Share on other sites More sharing options...
Adam Posted August 16, 2011 Share Posted August 16, 2011 By "after you click submit", do you mean in the PHP code handling the form data? If so, then you quite literally just need to use the str_replace function to match each smiley and convert it to the correct image as you output the text. Quote Link to comment https://forums.phpfreaks.com/topic/244921-how-to-change-smiley-text-to-image-in-textarea/#findComment-1258115 Share on other sites More sharing options...
rickmick Posted August 16, 2011 Author Share Posted August 16, 2011 Ok, the function is in my header.html. function insertSmiley(smiley) { var currentText = document.getElementById("comment"); var smileyWithPadding = " " + smiley + " "; currentText.value += smileyWithPadding; currentText.focus(); } This is in my story.html IF("{LOGGEDIN}"=="1"){<form name="form1" method="post" action="{SITE_URL}story.php?id={STORY_ID}" style="padding:0px;margin:0px;"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr id="creply" style="display:none;"> <td>Replying to comment by <span id="replynick"></span></td> </tr> <tr> <td><input type="button" value="Blue Text" name="btnBold" onClick="wrapText(document.getElementById('comment'),'<font color=blue><p><i>','</p></i></font>');"> After Clicking Quote, Highlight Reply Text and Click Button for Blue Text Quote </td> </tr> <tr> <img src="{SITE_URL}/smile/smile.gif" onclick="insertSmiley('')" /> <img src="{SITE_URL}/smile/beam.gif" onclick="insertSmiley(':-)')" /> <img src="{SITE_URL}/smile/bounce.gif" onClick="insertSmiley(':=(')" /> <img src="{SITE_URL}/smile/boxer.gif" onclick="insertSmiley('=')" /> <td><textarea name="comment" id="comment" style="width:95%;height:100px;"></textarea></td> </tr> <tr> <td><input type="submit" name="Submit" value="{LANG_ADDCOM2}"><input type="hidden" name="parentid" id="parentid" value="0"></td> </tr> <tr> </tr> </table> <br> </form>{:IF} I have this in my story.php trying it out. str_replace(':-)', '<img src="{SITE_URL}/smile/smile.gif" />', $comment); I have also tried this. $smiley = array(""); $replace = array ( '<img src="{SITE_URL}/smile/smile.gif">'); $result = str_replace($smiley, $replace, $comment); I have tried different one with no luck. Like I said when it come to a lot of things I am stupid. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/244921-how-to-change-smiley-text-to-image-in-textarea/#findComment-1258122 Share on other sites More sharing options...
rickmick Posted August 16, 2011 Author Share Posted August 16, 2011 Sorry, I meant that I have tried it out with this code. str_replace('', '<img src="{SITE_URL}/smile/smile.gif" />', $comment); Quote Link to comment https://forums.phpfreaks.com/topic/244921-how-to-change-smiley-text-to-image-in-textarea/#findComment-1258127 Share on other sites More sharing options...
AyKay47 Posted August 16, 2011 Share Posted August 16, 2011 should work.. what are your results..? Also, where is $comment coming from..? Quote Link to comment https://forums.phpfreaks.com/topic/244921-how-to-change-smiley-text-to-image-in-textarea/#findComment-1258130 Share on other sites More sharing options...
rickmick Posted August 16, 2011 Author Share Posted August 16, 2011 Attached is two images of what is taking place. comment1 image is after the user clicks the smile image and it inserts the smiley character. comment2 image is after the user hits add comment. As you can see just a charactor and not an image. I hope that this makes thing clear. Thanks again [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/244921-how-to-change-smiley-text-to-image-in-textarea/#findComment-1258142 Share on other sites More sharing options...
Adam Posted August 16, 2011 Share Posted August 16, 2011 You are displaying the contents of $result and not $comment aren't you? Quote Link to comment https://forums.phpfreaks.com/topic/244921-how-to-change-smiley-text-to-image-in-textarea/#findComment-1258177 Share on other sites More sharing options...
rickmick Posted August 16, 2011 Author Share Posted August 16, 2011 I know just enough php to make me dangerous. I believe it is a comment form posting the results. Quote Link to comment https://forums.phpfreaks.com/topic/244921-how-to-change-smiley-text-to-image-in-textarea/#findComment-1258190 Share on other sites More sharing options...
Adam Posted August 16, 2011 Share Posted August 16, 2011 $result = str_replace($smiley, $replace, $comment); Here you're assinging the replaced values into $result - $comment is not affected. If you're later displaying $comment theny you're displaying the comment without the replacements. Quote Link to comment https://forums.phpfreaks.com/topic/244921-how-to-change-smiley-text-to-image-in-textarea/#findComment-1258201 Share on other sites More sharing options...
rickmick Posted August 16, 2011 Author Share Posted August 16, 2011 Adam , I have tried this below in my php. I am lost on how to fix it. Is there a solution in php or in javascript for a replacement. $image = "{SITE_URL}/smile/smile.gif"; $code = ""; $comment = str_replace($code, $image, $comment); Quote Link to comment https://forums.phpfreaks.com/topic/244921-how-to-change-smiley-text-to-image-in-textarea/#findComment-1258244 Share on other sites More sharing options...
Adam Posted August 16, 2011 Share Posted August 16, 2011 I don't think given the code you've shown us we can help. Can you post all the code as it is? Quote Link to comment https://forums.phpfreaks.com/topic/244921-how-to-change-smiley-text-to-image-in-textarea/#findComment-1258269 Share on other sites More sharing options...
rickmick Posted August 16, 2011 Author Share Posted August 16, 2011 Attached id th story.php file and the is the overall_header.html is below. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset={LANG_CHARSET}"> <title>{SITE_TITLE} - {PAGE_TITLE}</title> <meta name="keywords" content=""> <meta name="description" content=""> <link href="{SITE_URL}templates/{TPL_NAME}/images/styles.css" type="text/css" rel="stylesheet"> <link rel="alternate" type="application/rss+xml" title="RSS Feed" href="{SITE_URL}xmlfeeds.php?cmd=popular" /> <script language="javascript" type="text/javascript" src="http://rickmick.com/blog/tinymce/jscripts/tiny_mce/tiny_mce.js"></script> <script language="javascript" type="text/javascript" src="http://rickmick.com/blog/tinymce/jscripts/tiny_mce/basic_config.js"></script> <script language="javascript" type="text/javascript" src="http://rickmick.com/blog/tinymce/jscripts/tiny_mce/tiny_mce.js"></script> <script language="javascript" type="text/javascript" src="http://rickmick.com/blog/tinymce/jscripts/tiny_mce/basic_config.js"></script> <script language="JavaScript" type="text/JavaScript"> <!-- var http = createRequestObject(); function createRequestObject() { var ro; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer") { ro = new ActiveXObject("Microsoft.XMLHTTP"); } else { ro = new XMLHttpRequest(); } return ro; } function digResponse() { if(http.readyState == 4) { var response = http.responseText; returned = response.split('|'); if(response.indexOf('|' != -1)) { var id=returned[1]; var numdigs=returned[2]; var status=returned[0]; if(status == '1') { document.getElementById('digbut'+id).innerHTML = '{LANG_DUGG}'; document.getElementById('numdigs'+id).innerHTML = numdigs; } else if(status == '2') { document.getElementById('digbut'+id).innerHTML = '{LANG_DUGG}'; } else if(status == '0') { document.getElementById('digbut'+id).innerHTML = '<a href="{SITE_URL}login.php">{LANG_LOGIN}<\/a>'; } } } } function cdigResponse() { if(http.readyState == 4) { var response = http.responseText; returned = response.split('|'); if(response.indexOf('|' != -1)) { var id=returned[1]; var numdigs=returned[2]; var status=returned[0]; if(status == '1') { document.getElementById('comd'+id).innerHTML = numdigs+' {LANG_DIGGS}'; document.getElementById('cup'+id).className = 'opacityit'; document.getElementById('cdown'+id).className = 'opacityit'; } else if(status == '2') { // Already dug comment document.getElementById('cup'+id).className = 'opacityit'; document.getElementById('cdown'+id).className = 'opacityit'; } else if(status == '0') { document.getElementById('comd'+id).innerHTML = '<a href="{SITE_URL}login.php">{LANG_LOGIN}<\/a>'; } } } } function buryResponse() { if(http.readyState == 4) { var response = http.responseText; returned = response.split('|'); if(response.indexOf('|' != -1)) { var id=returned[1]; var status=returned[0]; if(status == '0') { document.getElementById('digbut'+id).innerHTML = '<a href="{SITE_URL}login.php">{LANG_LOGIN}<\/a>'; } else { document.getElementById('digbut'+id).innerHTML = '{LANG_BURIED}'; } } } } function dig(id) { document.getElementById('digbut'+id).innerHTML = '{LANG_SENDING}'; http.open('get', '{SITE_URL}dig.php?i='+id); http.onreadystatechange = digResponse; http.send(null); } function digcom(comment_id,dir,story_id) { http.open('get', '{SITE_URL}dig.php?type=comm&i='+comment_id+'&story='+story_id+'&dir='+dir); http.onreadystatechange = cdigResponse; http.send(null); if(dir == 0) { dispcomment(comment_id,false,0); } } function bury_story(id) { if({LOGGEDIN} == 0) { document.getElementById('digbut'+id).innerHTML = '<a href="{SITE_URL}login.php">{LANG_LOGIN}<\/a>'; return; } http.open('get', '{SITE_URL}bury.php?i='+id); http.onreadystatechange = buryResponse; http.send(null); } function inclickcheck(field,def,val) { if(field.value == def) { field.value = val; } } function changeuser(field,but) { if(field.value == '') { document.getElementById(but).disabled = true; } else { document.getElementById(but).disabled = false; } } function checkavail(field) { username = document.getElementById(field).value; if(username.length < 4) { document.getElementById('availres').innerHTML = '{LANG_THEUSER} "'+username+'" {LANG_TOOSHORT}'; return; } else if(username.length > 16) { document.getElementById('availres').innerHTML = '{LANG_THEUSER} "'+username+'" {LANG_TOOLONG}'; return; } http.open('get', '{SITE_URL}signup.php?avail='+username); http.onreadystatechange = availResponse; http.send(null); } function availResponse() { if(http.readyState == 4) { var response = http.responseText; returned = response.split('|'); if(response.indexOf('|' != -1)) { var username=returned[0]; var status=returned[1]; if(status == 1) { document.getElementById('availres').innerHTML = '{LANG_THEUSER} "'+username+'" {LANG_ISAVAIL}'; } else { document.getElementById('availres').innerHTML = '{LANG_SORRY}, {LANG_THEUSER} "'+username+'" {LANG_ISTAK}'; } } } } function dispcomment(id,show,ctype) { if(ctype == 0) { if(show) { document.getElementById('commdesc'+id).style.display = ''; document.getElementById('commbut'+id).innerHTML = '{LANG_BURIED} [<a href="javascript:dispcomment('+id+',false,0);">{LANG_HIDEC}</a>]'; } else { document.getElementById('commdesc'+id).style.display = 'none'; document.getElementById('commbut'+id).innerHTML = '{LANG_BURIED} [<a href="javascript:dispcomment('+id+',true,0);">{LANG_SHOWC}</a>]'; } } else if(ctype == 1) { if(show) { document.getElementById('commdesc'+id).style.display = ''; document.getElementById('commbut'+id).innerHTML = '{LANG_BELOWTHRESH} [<a href="javascript:dispcomment('+id+',false,1);">{LANG_HIDEC}</a>]'; } else { document.getElementById('commdesc'+id).style.display = 'none'; document.getElementById('commbut'+id).innerHTML = '{LANG_BELOWTHRESH} [<a href="javascript:dispcomment('+id+',true,1);">{LANG_SHOWC}</a>]'; } } } function openWindow(theURL,winName,features) { window.open(theURL,winName,features); } function comreply(id,nickname) { if({LOGGEDIN} == 0) { alert('Please login before replying'); return; } document.getElementById('creply').style.display = 'none'; document.getElementById('replynick').innerHTML = nickname; document.getElementById('parentid').value = id; } function replycancel() { document.getElementById('creply').style.display = 'none'; document.getElementById('replynick').innerHTML = ''; document.getElementById('parentid').value = '0'; } function quote(element_id, textarea_id) { var textarea = null; var comment = null; if (document.getElementById) { textarea = document.getElementById(textarea_id); comment = document.getElementById(element_id).innerHTML; } else if (document.all) { textarea = document.all[textarea_id]; comment = document.all[element_id].innerHTML; } else if (document.layers) { textarea = document.layers[textarea_id]; comment = document.layers[element_id].innerHTML; } if (textarea) { textarea.focus(); var text = textarea.value + " " + " Replying to " + comment + ""; textarea.value = text.stripHTML(); textarea.focus(); } } String.prototype.stripHTML = function() { // What a tag looks like var matchTag = /<(?:.|\s)*?>/g; // Replace the tag return this.replace(matchTag, " "); }; function ChangeStyle() { document.getElementById("replynick").style.color="blue"; document.getElementById("replynick").style.fontFamily="Arial"; } function wrapText(el, openTag, closeTag) { if (el.setSelectionRange) { // W3C/Mozilla el.value = el.value.substring(0,el.selectionStart) + openTag + el.value.substring(el.selectionStart,el.selectionEnd) + closeTag + el.value.substring(el.selectionEnd,el.value.length); } else if (document.selection && document.selection.createRange) { // IE code goes here el.focus(); //or else text is added to the activating control var range = document.selection.createRange(); range.text = openTag + range.text + closeTag; } } function insertSmiley(smiley) { var currentText = document.getElementById("comment"); var smileyWithPadding = " " + smiley + " "; currentText.value += smileyWithPadding; currentText.focus(); } --> </script> </head> <body> <div id="headermain"> <div id="headercontainer"> <div class="headerlogo"> <div class="logo"> <a href="{SITE_URL}" class="logo">{SITE_TITLE}</a> </div> </div> <div class="headeright"> <div class="headerrighttop"> <div align="right"> IF("{LOGGED_IN}"=="0"){ <div class="headersignupouter"> <div class="headersignupicon"><a href="{SITE_URL}signup.php"></a></div> <div class="headersignuptext"><a href="{SITE_URL}register.php">{LANG_SIGNUP}</a></div> <div class="aclear"></div> </div> <div class="headerloginouter"> <div class="headerloginicon"><a href="{SITE_URL}login.php"></a></div> <div class="headerlogintext"><a href="{SITE_URL}login.php">{LANG_LOGIN}</a></div> <div class="aclear"></div> </div> {:IF} IF("{LOGGED_IN}"=="1"){ <div class="headereditprofouter"> <div class="headerloginicon"><a href="{SITE_URL}editprofile.php"></a></div> <div class="headereditproftext"><a href="{SITE_URL}editprofile.php">{LANG_EDITPROFILE}</a></div> <div class="aclear"></div> </div> <div class="headerlogoutouter"> <div class="headerloginicon"><a href="{SITE_URL}logout.php"></a></div> <div class="headerlogintext"><a href="{SITE_URL}logout.php">{LANG_LOGOUT}</a></div> <div class="aclear"></div> </div> <div class="aclear"></div> </div> <div class="headereditprofouter"> <div class="headerloginicon"><a href="{SITE_URL}editprofile.php"></a></div> <div class="headereditproftext"><a href="{SITE_URL}myaccount.php">My Account</a> </div> {:IF} </div> </div> <div class="headerrightbottom"> <div align="right"> <form name="form1" method="get" action="{SITE_URL}search.php" style="padding:0px;margin:0px;"> <div class="searchbox"> <input name="q" type="text" id="q" size="25" style="width:250px;" /> </div> <div class="searchbutton"> <input name="submit" type="image" src="{SITE_URL}templates/{TPL_NAME}/images/search.gif" width="78" height="34" align="absmiddle" vspace="0" hspace="0" style="padding:0px;margin:0px;" border="0"> </div> </form> </div> </div> </div> </div> </div> <div id="navbar"> <div id="navbarcontainer"> <div id="topnav"> <ul> {LOOP: CATS_MAIN} <li><a title="{CATS_MAIN.cat_title}" href="{CATS_MAIN.cat_url}">{CATS_MAIN.cat_title}</a></li> {/LOOP: CATS_MAIN} </ul> </div> </div> </div> IF("{SUBCAT_COUNT}"!="0"){ <div id="navbar_sub"> <div id="navbarcontainer_sub"> <div id="subnav"> <ul> {LOOP: CATS_CUR} <li><a title="{CATS_CUR.cat_title}" href="{CATS_CUR.cat_url}">{CATS_CUR.cat_title}</a></li> {/LOOP: CATS_CUR} </ul> </div> </div> </div> {:IF} This is the story.html {OVERALL_HEADER} </head> <body> <div id="container"> <div class="aclear"></div> <div id="headerbar"></div> <div class="aclear"></div> <div id="main"> <div class="maincontent"> <div class="postage"> <div class="rating1"> <div class="ratingbutton"> <a href="{STORY_URL}">{STORY_DIGS}</a> <div class="digstext">{LANG_DIGGS}</div> </div> <div class="duggbutton" id="digbut{STORY_ID}"> IF("{USER_DUGG}"=="1"){<a href="{STORY_URL}">{LANG_DUGG}</a>{:IF} IF("{USER_DUGG}"=="0"){<a href="javascript:dig({STORY_ID});">{LANG_DIGIT}</a>{:IF} </div> <div class="aclear"></div> </div> <div class="mainpost1"><div class="posttitle"><a href="{STORY_URL}">{STORY_TITLE}</a></div> <div class="postdetails">{LANG_SUBBY} {STORY_USER_NAME} {STORY_AGO} {LANG_AGO} (via {STORY_DOMAIN})</div> <div class="postcontent">{STORY_DESC}</div> <div class="postapps"> <div class="postappscommentsicon"></div> <div class="postappscommentslink"><a href="{SITE_URL}story.php?id={STORY_ID}">{STORY_COMMENTS} {LANG_COMS}</a></div> <div class="postappssendicon"></div> <div class="postappssendlink"><a href="javascript:bury_story({STORY_ID});">{LANG_BURY}</a></div> </div> </div> <div class="aclear"></div> </div> <br /><br /> <div class="popbar"> <div id="tabsB"> <ul> <li id="current"><a href="{SITE_URL}story.php?id={STORY_ID}"><span>{LANG_COMS} ({STORY_COMMENTS})</span></a></li> <li><a href="{SITE_URL}story.php?id={STORY_ID}&cmd=dugg"><span>{LANG_WHODUG}</span></a></li> <li><a href="{SITE_URL}story.php?id={STORY_ID}&cmd=email"><span>{LANG_EMAILLINK}</span></a></li> </ul> </div> </div> <br> <strong>{LANG_COMS}</strong><br> {LOOP: COMMENTS} <table width="100%" border="0" cellpadding="0" cellspacing="0"><tr> IF("{COMMENTS.parent_id}"!="0"){<td width="70"> </td>{:IF} <td> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="25" valign="middle" bgcolor="#e4edf4"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table border="0" cellpadding="0" cellspacing="0"> <tr> <td width="20" align="center"><img src="{SITE_URL}{COMMENTS.avatar}"></td> <td class="comline"> by <a href="{COMMENTS.user_link}">{COMMENTS.username}</a> {COMMENTS.ago} {LANG_AGO}</td> </tr> </table></td> <td align="right"><div id="commbut{COMMENTS.comment_id}" class="subline">IF("{COMMENTS.dug}"=="-1"){{LANG_BURIED} [<a href="javascript:dispcomment({COMMENTS.comment_id},true,0);">{LANG_SHOWC}</a>]{:IF}IF("{COMMENTS.hide}"=="1"){{LANG_BELOWTHRESH} [<a href="javascript:dispcomment({COMMENTS.comment_id},true,1);">{LANG_SHOWC}</a>]{:IF}</div></td> <td width="80" align="right"><div class="comdigs" id="comd{COMMENTS.comment_id}">{COMMENTS.comment_digs} {LANG_DIGGS}</div></td> <td width="50" align="center"><table border="0" cellspacing="0" cellpadding="0"> <tr align="center"> <td><a href="javascript:digcom({COMMENTS.comment_id},0,{STORY_ID});"><img IF("{COMMENTS.dug}"!="0"){class="opacityit"}{:IF} id="cdown{COMMENTS.comment_id}" src="{SITE_URL}templates/{TPL_NAME}/images/arrow_down.gif" border="0" width="16" height="16"></a></td> <td><a href="javascript:digcom({COMMENTS.comment_id},1,{STORY_ID});"><img IF("{COMMENTS.dug}"!="0"){class="opacityit"}{:IF} id="cup{COMMENTS.comment_id}" src="{SITE_URL}templates/{TPL_NAME}/images/arrow_up.gif" border="0" width="16" height="16"></a></td> </tr> </table></td> </tr> </table></td> </tr> <tr id="commdesc{COMMENTS.comment_id}" IF("{COMMENTS.dug}"=="-1"){style="display:none;"{:IF}IF("{COMMENTS.hide}"=="1"){style="display:none;"{:IF}><td>{COMMENTS.comment_desc}</td></tr> IF("{COMMENTS.parent_id}"=="0"){<tr><td align="right"><span class="subline">[<a href="#commentbox" onClick="comreply({COMMENTS.comment_id},'{COMMENTS.username}, {COMMENTS.comment_desc}');ChangeStyle();javascript:quote('replynick','comment')">Quote</a>]</span></td></tr>{:IF} </table> </td></tr> </table> <br> {/LOOP: COMMENTS} <br> <br> <a name="commentbox"></a> <strong>{LANG_ADDCOM}</strong><br> IF("{LOGGEDIN}"=="0"){{LANG_PLEASE} <a href="{SITE_URL}login.php">{LANG_LOGIN}</a> {LANG_OR} <a href="{SITE_URL}signup.php">{LANG_SIGNUP}</a> {LANG_TOLEAVE}{:IF} IF("{LOGGEDIN}"=="1"){<form name="form1" method="post" action="{SITE_URL}story.php?id={STORY_ID}" style="padding:0px;margin:0px;"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr id="creply" style="display:none;"> <td>Replying to comment by <span id="replynick"></span></td> </tr> <tr> <td><input type="button" value="Blue Text" name="btnBold" onClick="wrapText(document.getElementById('comment'),'<font color=blue><p><i>','</p></i></font>');"> After Clicking Quote, Highlight Reply Text and Click Button for Blue Text Quote </td> </tr> <tr> <img src="{SITE_URL}/smile/smile.gif" onclick="insertSmiley('')" /> <td><textarea name="comment" id="comment" style="width:95%;height:100px;"></textarea></td> </tr> <tr> <td><input type="submit" name="Submit" value="{LANG_ADDCOM2}"> <input type="hidden" name="parentid" id="parentid" value="0"></td> </tr> <tr> </tr> </table> <br> </form>{:IF} <br> <br></td> </tr> </table> </div> </div> </div> <div class="aclear"> </div> </div> {OVERALL_FOOTER} [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/244921-how-to-change-smiley-text-to-image-in-textarea/#findComment-1258274 Share on other sites More sharing options...
Adam Posted August 17, 2011 Share Posted August 17, 2011 [...] if(isset($_POST['comment'])) { if(isset($_SESSION['user_id'])) { $errors = 0; $image = "{SITE_URL}/smile/smile.gif"; $code = ""; $comment = str_replace($code, $image, $comment); $all_tags_filtered = strip_tags($_POST['comment']); $some_tags_filtered = strip_tags($_POST['comment'], '<p><strong><em><i>'); $_POST['comment'] = substr($_POST['comment'],0,500); [...] There are some issues with your code here, but most importantly you're converting the smiley at the wrong point. Instead of doing it as you INSERT it into the database, you should do it as you SELECT it (i.e. when you output it). This means the user/admin is able to modify the comment without blocks of HTML, it doesn't take up as much memory, and doesn't affect the maximum length of a post. Also that way if you ever wish to change the mark-up of the HTML (add a class to the smiley images for example), you don't need to do any complicated UPDATE within the database. This should also be the case for any other BBCode you may use. Try moving the logic and come back if you run into any issues. Quote Link to comment https://forums.phpfreaks.com/topic/244921-how-to-change-smiley-text-to-image-in-textarea/#findComment-1258492 Share on other sites More sharing options...
rickmick Posted August 17, 2011 Author Share Posted August 17, 2011 This was a addon to my site. I don't have a clue on how to fix it. I guess I will remove all codes from my site and move on. Thanks, again. Quote Link to comment https://forums.phpfreaks.com/topic/244921-how-to-change-smiley-text-to-image-in-textarea/#findComment-1258610 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.