2

I get a strange symbol when i compile symbol on line 36 of this code:

I am not sure what you press to get that nice box where you can write the code. Please dont downvote me. Edit the post. I have tried to indet the code with 4 spaces but nothing seems to work. Sorry for the inconvinience.

\documentclass{article}
   \usepackage{listings,xcolor}
   \definecolor{dkgreen}{rgb}{0,.6,0}
   \definecolor{dkblue}{rgb}{0,0,.6}
   \definecolor{dkyellow}{cmyk}{0,0,.8,.3}

   \lstset{
     language        = php,
     basicstyle      = \small\ttfamily,
     keywordstyle    = \color{dkblue},
     stringstyle     = \color{red},
     identifierstyle = \color{dkgreen},
     commentstyle    = \color{gray},
     emph            =[1]{php},
     emphstyle       =[1]\color{black},
     emph            =[2]{if,and,or,else},
     emphstyle       =[2]\color{dkyellow}}

   \begin{document}
   \begin{lstlisting}
   <?php

   $username = $_POST["username"];
   $password = $_POST["password"];

   $pass = md5($passwort);

   // another comment
   if($username=="User" and
   $pass=="123456")
       {
       echo "Welcome";
       }
    else
       {
       echo "Try again.";
       }
    ?>
    \end{lstlisting}
    \end{document}

1 Answer 1

3

You are getting the blank spaces in strings. To eliminate them use showstringspaces=false (initially true) in the option.

\documentclass{article}
   \usepackage{listings,xcolor}
   \definecolor{dkgreen}{rgb}{0,.6,0}
   \definecolor{dkblue}{rgb}{0,0,.6}
   \definecolor{dkyellow}{cmyk}{0,0,.8,.3}

   \lstset{
     language        = php,
     basicstyle      = \small\ttfamily,
     keywordstyle    = \color{dkblue},
     stringstyle     = \color{red},
     identifierstyle = \color{dkgreen},
     commentstyle    = \color{gray},
     emph            =[1]{php},
     emphstyle       =[1]\color{black},
     emph            =[2]{if,and,or,else},
     showstringspaces=false,                   %% <--- here
     emphstyle       =[2]\color{dkyellow}}

   \begin{document}
   \begin{lstlisting}
   <?php

   $username = $_POST["username"];
   $password = $_POST["password"];

   $pass = md5($passwort);

   // another comment
   if($username=="User" and
   $pass=="123456")
       {
       echo "Welcome";
       }
    else
       {
       echo "Try again.";
       }
    ?>
    \end{lstlisting}
    \end{document}

enter image description here

3
  • Thank you! May I ask how you did to show the code in the box?
    – Rectifier
    Mar 19, 2015 at 2:29
  • 1
    @Rectifier Select the code and press {} button or cntrl + K. i.sstatic.net/jlBWI.png
    – user11232
    Mar 19, 2015 at 2:32
  • 1
    @Rectifier Happy TeXing and nice time to you too. :)
    – user11232
    Mar 19, 2015 at 2:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .