-7

This is how I have made so that you can see the code on the website. but every time I change it or upload then write it just \ by itself. can not figure out what the problem is at all

so here it seems when I copy from the page:

            <?php 
    $hej = \"Hej\";
    $jesper = \"Jesper\";
    echo $hej . \" \" . $jesper;
     ?>     

When I view the code on the page so doing it here like this;

<?php
if ($dw = "PHP" or $dw = "MySQLi") {
    ?>
    <code>
        <pre>
            <?php
            $html = "<?php \n";
            $html .= $tekst;
            $html .="\n ?>";
            echo htmlentities($html);
            ?>
        </pre>
    </code>
    <?php
} elseif ($dw = "") {
    echo "<p>Not code her!!</p>";
} else {
    ?>
    <code>
        <pre>
    <?php echo $tekst; ?>
        </pre>
    </code>
            <?php
        }
        ?>
</div>

The do it only by "" when I made them in my code so do the instance like this \"Blah blah \". but I want it just to do it like this "blah blah" and show code normally as I write it:

This is what my code out when I put them on the page and updater content on the page.

function opret_artikler()
 {
     $pb = null;

     include "inc/class.upload.php";
     $handle = new Upload($_FILES["file"]);

     if($handle->uploaded)
     {
         $handle->image_resize = true;
         $handle->image_ratio_crop = true;
         $handle->image_y = 90;
         $handle->image_x = 191;
         $handle->Process("artikler_img");

         //til profil billede lign..
         $handle->image_resize = true;
         $handle->image_ratio_crop = true;
         $handle->image_y = 75;
         $handle->image_x = 75;
         $handle->Process("artikler_img/lille");
         $pb = $handle->file_dst_name;
     }

     $tu = $_POST["title_url"];

     $from = array(".", "/", "-", '"', "'", " ", "æ", "Æ", "ø", "Ø", "å", "Å");
     $to = array("-", "-", "-", "", "", "-", "ae", "Ae", "oe", "Oe", "aa", "Aa");
     $alias = strtolower(str_replace($from, $to, $tu));    

     if ($stmt = $this->mysqli->prepare("INSERT INTO `artiker` (`title`, `kort`, `video`, `tekst`, `tag`, `url`, `img`, `img_title`, `dw`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")) { 

         $stmt->bind_param('sssssssss', $title, $kort, $video, $tekst, $tag, $url, $img, $img_title, $dw);

         /* Sæt værdier på parametrene */
         $title = $_POST['title']; 
         $kort = $_POST['kort'];
         $video = stripslashes($_POST['video']);
         $tekst = $_POST['tekst'];
         $tag = $_POST["tag"];
         $url = $alias;
         $img = $pb;
         $img_title = $_POST["img_title"];
         $dw = $_POST["dw"];

         /* Eksekver forespørgslen */
         $stmt->execute();

         /* Luk statement */
         $stmt->close();

         ?>
         <script language="javascript" type="text/javascript">  
             window.location.href = "/artikler-side/";  
         </script> 
         <?php

     } else {
         /* Der er opstået en fejl */
         echo 'Der opstod en fejl i erklæringen: ' . $this->mysqli->error;
     }    
 }

function ret_artikler()
 {
 ?>
 <div class="span7 clearfix">
     <?php
     if(isset($_POST["opret"]))
     {
         if(empty($_POST["tekst"]))
         {
             echo "Skrive <b>title</b> til artiklen!<br />";
         }
         elseif(empty($_POST["kort"]))
         {
             echo "Skrive <b>Kort tekst</b> til artiklen!<br />";
         }
         else
         {
             if ($stmt = $this->mysqli->prepare("UPDATE `artiker` SET `godkendt`=?, `kort`=?, `tekst`=? WHERE `id`=?")) { 

                 /* Bind parametre */
                 $stmt->bind_param('issi', $godkendt, $kort, $tekst, $id);
                 $godkendt = 0;
                 $kort = $_POST["kort"];
                 $tekst = $_POST["tekst"];
                 $id = $_GET["id"];

                 /* Eksekver forespørgslen */
                 $stmt->execute();

                 /* Luk statement */
                 $stmt->close();

                 ?>
                 <script language="javascript" type="text/javascript">  
                     window.location.href = "/admin/";  
                 </script> 
                 <?php

             } else {
                 /* Der er opstået en fejl */
                 echo 'Der opstod en fejl i erklæringen: ' . $this->mysqli->error;
             }
         }
     }
     ?>
 </div>
 <div class="span7 clearfix">
 <?php
 if ($stmt = $this->mysqli->prepare("SELECT `kort`, `tekst` FROM `artiker` WHERE `id` = ?")) { 

 /* Bind parametre */
 $stmt->bind_param('i', $id);

 /* Sæt værdier på parametrene */
 $id = $_GET['id'];

 /* Eksekver forespørgslen */
 $stmt->execute();
 $stmt->store_result();

 /* Bind resultatet */
 $stmt->bind_result($kort, $tekst);

 /* Hent rækker og udskriv data */
 while ($stmt->fetch()) {
 ?>
 <form action="#" method="post">
     <table width="100%">
     <tr>
         <td>Kort:</td>
         <td><input type="text" name="kort" maxlength="150" value="<?php echo $kort;?>"></td>
     </tr>
     </table>
     <textarea name="tekst" rows="15" cols="80" style="width: 90%"><?php echo $tekst;?></textarea>
     <input type="submit" name="opret" value="Opret Indhold">
 </form>
 <?php
 }
     $stmt->close();
 } else {
     echo 'Der opstod en fejl i erklæringen: ' . $this->mysqli->error;
 }
 ?>

 </div>
 <?php
 }

I get no errors along the way.

what I want out of this problem is to show the code without problems on the side with \ or similar.

You can see the problem here: Problem here

Daedalus
  • 7,586
  • 5
  • 36
  • 61
Jesper
  • 29
  • 2
  • So.. you escape the string signifiers and you are surprised when your code doesn't parse? If you want to include quotes in your string, just escape them after you enclose the string in quotes, like this: `$var = "\"string\"";` – Daedalus Feb 23 '13 at 21:47
  • *"I get no errors along the way."*... see http://stackoverflow.com/a/14504459/398242 – Wesley Murch Feb 23 '13 at 21:51

1 Answers1

2
$hej = \"Hej\";

this (\") is what you call escaping. You only need to do it when you need " in your string-variable. so what you forgot is your quotes around your string

$hej="\"Hej\"";

or

$hej='"Hej"';
Stef Geysels
  • 1,023
  • 11
  • 27