0

I have the following piece of code and wish to display it as text in a webpage. How can I do it? I wat the code mentioned below to be displayed as text in a webpage. The page might be either a .html page or a .php page. Kindly help.

<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Log in!</title>
 <style type="text/css">
  div {
     width:300px;
     height:120px;
     margin: 0px auto;
     margin-top: 100px;
      padding: 30px 20px;
      border:2px solid #00F;
     background-color:#0CF;
     border-radius:10px;
    }

 span{
    margin:0px auto;
     color:#F00;
      font-family:Verdana, Geneva, sans-serif;
     font-size:12px;
  }

 </style>
 </head>

<body>
 </body>
 <?php
 require_once('conn.php');

$sql="select * from contacts where contacts_id=14";
 $result=$mysqli->query($sql);
 $row=$result->fetch_array();
 if( isset($_POST['id']) && $row['email']==$_POST['id'] && $_POST['password']==$row['password'])
 {
     header("location:view.php")    ;
      $_SESSION['sid']= $row['email'];
    $flag=1;
 }
 ?>

 <div>
 <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
 <table align="center" border="0">
   <tr>
      <td>Id</td>
      <td>:</td>
      <td><input type="text" name="id" placeholder="Email" /></td>
    </tr>
    <tr>
    <td>Password</td>
      <td>&:</td>
      <td><input type="password" name="password" /></td>
    </tr>
    <tr>
      <td></td>
   <td colspan="2"><input type="submit" value="Log In!" /></td>
    </tr>
 </table>
  </form>
     <?php
      if (isset($_POST['id']) && isset($_POST['password']) && $flag==0)
     {
           echo "<center><span>Invalid Id/Password</span></center>";    
      }

   ?>
    </div>
   </body>
   </html>
5
  • If your PHP parser is parsing your PHP tags in your HTML page then replace the < character with &lt;. As far as showing code in HTML you can try putting it inside <code>..</code> Commented Mar 10, 2015 at 13:44
  • You can give the file a .phps extension, or use highlight_file() php.net/manual/en/function.highlight-file.php - If that'swhat this question is about. Or, are you asking to do a "printer-friendly" method? Your question is a bit unclear. Commented Mar 10, 2015 at 13:46
  • Thanks Fred for your reply. I am not looking for a printerfriendly version. I only want the code to be displayed as it is on a web page. Commented Mar 11, 2015 at 11:37
  • 1
    You're welcome. You can try either method I posted in my comment above. To call me out directly in order for me to get a notification, add the @ symbol followed by my name, should you need more info. Commented Mar 11, 2015 at 15:11
  • @DebashisSikdar I have posted an answer for you below. Commented Mar 11, 2015 at 15:24

5 Answers 5

1

You can also use highlight_string() function

 <?php

 highlight_string("YOUR STRING/CODE GOES HERE");
 ?>
Sign up to request clarification or add additional context in comments.

Comments

1
$gen_query_data= htmlspecialchars(' $'.$db_val_clean.'_ser = $_POST["'.$sel_name_clean.'_ser"];')."<br>";

     echo $gen_query_data;  

please change your variables

Comments

0

if your server isn't set up to process .html for the php tag, you're fine to do exactly what you've done.

You can also use this: &lt;?php which would render as <?php but not be seen by PHP.

Comments

0

One option you can use is PHP's highlight_file() function:

<?php
highlight_file("your_file.php");
?>

You can also use .html file extensions highlight_file("your_file.html").

Even a .txt file extension highlight_file("your_file.txt").

Consult:

1 Comment

@JayBlanchard Afternoon Sam!
-1

this question is pretty old , but as long as no one used this solution so this would be helpful .

using htmlspecialchars :

htmlspecialchars — Convert special characters to HTML entities

echo htmlspecialchars("your special character goes here");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.