当我编译此代码第 36 行的符号时,我得到一个奇怪的符号:
我不知道你按了什么才能得到那个可以写代码的漂亮框。请不要给我差评。编辑帖子。我尝试用 4 个空格插入代码,但似乎不起作用。抱歉给您带来不便。
\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
字符串中出现了空格。要消除空格,请使用选项中的showstringspaces=false
(initially )。true
\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}