When writing PHP code in the browser, usually we want to only display the code without executing it. This need is mainly to show code examples without letting the browser interpret and execute PHP code. In actual development, we can achieve this goal in some simple ways.
A common method is to use the HTML <div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"></pre><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div>
tag, which retains the formatting of the code and displays it as preformatted text without interpreting the HTML or PHP code within it. .
Another method is to use PHP's highlight_file
function, which will highlight the PHP code in the specified file and output it to the browser without executing it. PHP code.
Below I will show specific code examples of these two methods respectively:
<div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"></pre><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div>
tag <!DOCTYPE html> <html> <head> <title>显示PHP代码示例</title> </head> <body> <pre class="brush:php;toolbar:false"> <?php // 这里写PHP代码示例 echo "Hello, World!"; ?>