Jump to content

textarea probelm with htmlentities


MDanz

Recommended Posts

In the textarea it displays this

 

car1 >>car2 when it should display car1>>car2

 

this is my code, here's what i tried to resolve it...

 

$sumz= "car1>>car2";

$textsearch = array('<','>');
$textreplace = array ('<','>');
$textareatext = "$sumz";


			echo "<div style='display:none;' id='$number'>".str_replace($textsearch,$textreplace,htmlentities($textareatext))."</div>";

 

it still displays car1 >>car2

 

:confused:

 

Link to comment
https://forums.phpfreaks.com/topic/205412-textarea-probelm-with-htmlentities/
Share on other sites

its displaying perfectly fine at my place..

 

try this code... it doesn't work.  put your mouseover "test".

 

<?php
$sumz= "car1>>car2";

$textsearch = array('&lt;','&gt;');
$textreplace = array ('<','>');
$textareatext = "$sumz";


            echo "<div style='display:none;' id='1'>".str_replace($textsearch,$textreplace,htmlentities($textareatext))."</div>";
		echo "<table><tr><td onmouseover='Test(1);'>test </td></tr></table>";

echo "<br /><br /><textarea name='reply' id='reply' style='color: #000000; overflow: hidden; font-size:15px; height:52px; width:500px; text-align: left' readonly='readonly'  >test</textarea>";
?>

<script type="text/javascript">
function Test(number) {
var newtext = document.getElementById(number).innerHTML;
   document.getElementById('reply').value = newtext;
   }
</script>

Now that you have bothered to show what you are doing and what your code really is (you could have solved this 2 days a go in your original thread on this problem), here are a couple of solutions - http://www.webdeveloper.com/forum/archive/index.php/t-136026.html

 

Your str_replace() is not doing anything because the strings you are searching for don't exist (and if they did, outputting < and > would break the HTML) -

<?php
$sumz= "car1>>car2";

$textareatext = $sumz;

            echo "<div style='display:none;' id='1'>". htmlentities($textareatext) ."</div>";
         echo "<table><tr><td onmouseover='Test(1);'>test </td></tr></table>";

echo "<br /><br /><textarea name='reply' id='reply' style='color: #000000; overflow: hidden; font-size:15px; height:52px; width:500px; text-align: left' readonly='readonly'  >test</textarea>";
?>

<script type="text/javascript">

function get_ents(str){
var temp=document.createElement("pre");
temp.innerHTML=str;
return temp.firstChild.nodeValue;
}

function Test(number) {
var newtext = document.getElementById(number).innerHTML;
   document.getElementById('reply').value = get_ents(newtext);
   }
</script>

Archived

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

×
×
  • Create New...

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.