1

I want to show this code like a text type in web page. i am using program language is PHP

<div>
    <a href="js/index.html">Js</a></div>
    <div><a href="php/index.php">PHP</a></div>
    <div><a href="test/index.html">Test</a></div>
    <input id="in" type="text">
    <div class="">Off season <span id="out"></span> this</div>
    <script src="js/assets/jquery.js"></script>
    <script>
        $("#in").keyup(function () {
            var text = this.value;
            $('#out').text(text);
        })
    </script>
</div>
3
  • So, just to be clear, you want it to be shown as actual code and not be parsed? Commented Nov 11, 2015 at 7:47
  • I am not sure what you are trying to achieve, but to show JavaScript text without it being parsed you might try to use <pre> and </pre> respectively. However, a more beautiful output might be achieved with CSS. Commented Nov 11, 2015 at 7:54
  • I cant see html tags in my browser. that's my problem. it's showing page source only.. Commented Nov 11, 2015 at 7:57

4 Answers 4

1

HTML escape

&lt;div&gt;
    &lt;a href=&quot;js/index.html&quot;&gt;Js&lt;/a&gt;&lt;/div&gt;
    &lt;div&gt;&lt;a href=&quot;php/index.php&quot;&gt;PHP&lt;/a&gt;&lt;/div&gt;
    &lt;div&gt;&lt;a href=&quot;test/index.html&quot;&gt;Test&lt;/a&gt;&lt;/div&gt;
    &lt;input id=&quot;in&quot; type=&quot;text&quot;&gt;
    &lt;div class=&quot;&quot;&gt;Off season &lt;span id=&quot;out&quot;&gt;&lt;/span&gt; this&lt;/div&gt;
    &lt;script src=&quot;js/assets/jquery.js&quot;&gt;&lt;/script&gt;
    &lt;pre&gt;
        $(&quot;#in&quot;).keyup(function () {
            var text = this.value;
            $(&#x27;#out&#x27;).text(text);
        })
    &lt;/pre&gt;
&lt;/div&gt;
Sign up to request clarification or add additional context in comments.

1 Comment

:) . with <pre></pre> better.
1

There are plenty of good answers, but another one that could be used would be:

highlight_string

<?php
$var = '<div>
    <a href="js/index.html">Js</a></div>
    <div><a href="php/index.php">PHP</a></div>
    <div><a href="test/index.html">Test</a></div>
    <input id="in" type="text">
    <div class="">Off season <span id="out"></span> this</div>
    <script src="js/assets/jquery.js"></script>
    <script>
        $("#in").keyup(function () {
            var text = this.value;
            $("#out").text(text);
        })
    </script>
</div>';

highlight_string($var);
?>

Answer was inspired / gotten from here https://stackoverflow.com/a/28965609/2285345

Comments

0

In addition to my comment:

<div>
    <a href="js/index.html">Js</a></div>
    <div><a href="php/index.php">PHP</a></div>
    <div><a href="test/index.html">Test</a></div>
    <input id="in" type="text">
    <div class="">Off season <span id="out"></span> this</div>
    <script src="js/assets/jquery.js"></script>
    <pre>
        $("#in").keyup(function () {
            var text = this.value;
            $('#out').text(text);
        })
    </pre>
</div>

You can use w3schools as a starting point.

Comments

0

You should wrap it in <pre>Your code goes here</pre> tags.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.