I want to display code characters on an HTML page. But no matter what I try it always renders HTML characters. pre or code doesn't work. How can I do this?
I want to display code characters on an HTML page. But no matter what I try it always renders HTML characters. pre or code doesn't work. How can I do this?
To display HTML tags within a browser, you can surround the output with
<xmp><p>HTML<p></xmp> tags
This is the easy way to fix this problem. but this tag already deprecated.
for more details : xmp
You can use htmlentities.But you can't use this inside the JavaScript file. because JavaScript runs in the user's browser. PHP runs on the server.
<code>
<?php print htmlentities('<p>HTML</p>');?>
</code>
Download tinymce From
https://www.tinymce.com/download/
<html>
<head>
<script src='tinymce/js/tinymce.min.js'></script>
<script>
tinymce.init({
selector: '#myTextarea',
height: 300,
width:800,
theme: 'modern',
plugins: [
'advlist autolink lists link image charmap print preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen',
'insertdatetime media nonbreaking save table contextmenu directionality',
'emoticons template paste textcolor colorpicker textpattern imagetools'
],
toolbar1: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
toolbar2: 'print preview media | forecolor backcolor emoticons',
image_advtab: true
});
</script>
</head>
<body>
<textarea name="myTextarea" id="myTextarea" rows="4" cols="50">Hello Ashish</textarea>
<input type='submit' value='save'/>
</body>
</html>
try wrapping HTML content in <textarea></textarea> For ex: <pre> <textarea> <html> </html> </textarea> </pre> Works in awesome way. You don't have to use obsolete <XMP> example tag. <textarea> tag will wrap the content in text area. Try out !