YOURLS网站index.php添加ASCII艺术Logo后页面空白求助
Hey there! Let's figure out why your YOURLS page went blank after adding the ASCII logo—there are a few straightforward fixes here:
1. Critical Syntax Error in PHP Closing Tag
First off, your code has a typo that's breaking PHP parsing entirely:
<pre style="font-family: 'Courier New', Courier, monospace"><?php echo $asciiart; ?/></pre>
See that ?/ at the end? That's not a valid PHP closing tag. It should be ?> instead. This invalid tag triggers a fatal PHP error, and since YOURLS typically hides error messages in production, you get a blank page instead of a helpful alert. Fix this tag first, and that alone might resolve the issue.
2. Improperly Formatted $asciiart String
Long ASCII art strings often contain line breaks, quotes, or special characters that can break PHP string syntax if not handled correctly. For example:
- If you wrap the ASCII in double quotes (
"..."), any double quotes inside the art will need to be escaped with a backslash (\"). - If you use single quotes (
'...'), line breaks won't render properly unless you use explicit\ncharacters.
The easiest way to handle long ASCII art is to use PHP's Nowdoc syntax (which treats content as plain text, no escaping needed):
// Define this in your PHP code (before you echo it!) $asciiart = <<<'ASCII' _______ _______ _______ _______ | || || || | | ___|| ___|| ___|| ___| | |___ | |___ | |___ | |___ | ___|| ___|| ___|| ___| | | | | | | | |___ |___| |___| |___| |_______| ASCII;
This keeps your ASCII art intact without needing to escape any characters.
3. Placement of Code Matters
Make sure:
- The
$asciiartvariable is defined in a PHP code block (inside<?php ... ?>) before you try to echo it. If you echo it before defining the variable, PHP will throw an "undefined variable" error, which can also cause a blank page. - Your
<pre>block with the echo is placed in the HTML output section of index.php (inside the<body>tag, where content is rendered), not inside a PHP code block.
Quick Debugging Tip
To see exactly what's going wrong instead of staring at a blank page, enable PHP error display temporarily by adding this at the very top of your index.php:
error_reporting(E_ALL); ini_set('display_errors', 1);
This will show you the exact error message (like syntax errors or undefined variables) so you can fix it faster.
内容的提问来源于stack exchange,提问作者Jinreiyu

