Reputation: 29
From this code.
<form method="get">
<div align="center"><textarea name="post" ></textarea></div>
<div align="center"><input type="submit" value="Submit"></div>
</form>
<?
$aaa = $post;
$new_aaa=str_replace(array(
'a',
'b'
), array(
'A',
'B'
), $aaa);
?>
<textarea readonly="true" cols="100" rows="3" name="post" >
<? echo $new_aaa; ?>
</textarea>
</div>
If we write in the form of javascript to do here?
If you do not understand, it is to get value from textarea
and then use the str_replace
function as a type, but the output is A, help me write a little PHP I own one, but never wrote JS.
Sorry for bad English, I've used Google Translate.
Upvotes: 0
Views: 420
Reputation: 29
Now I can do then.
Thank you all comments.
<form method="get" onsubmit="return Convert();">
<div align="center"><textarea name="post" id="post" ></textarea></div>
<div align="center"><input type="submit" value="Submit"></div>
</form>
<script>
function Convert()
{
var p = document.getElementById ("post").value;
var replace = {
'1' : "\u0e45",
'2' : "\u002F",
};
for(var i in replace)
{
var regex = new RegExp(i,'g');
p = p.replace(regex,replace[i]);
}
document.getElementById ("post2").value= p;
return false;
}
</script>
<textarea readonly="true" cols="100" rows="3" name="post2" id="post2" >
</textarea>
Upvotes: 0
Reputation: 4179
<form method="get" onSubmit='Convert()'>
<div align="center"><textarea name="post" id="post" ></textarea></div>
<div align="center"><input type="submit" value="Submit"></div>
</form>
........ In script
<script>
function Convert()
{
var p = document.getElementById ("post").value;
p = p.replace(/a/g,”A”);
p = p.replace(/b/g,”B”);
document.getElementById ("post").value= p;
}
</script>
Upvotes: 1