如何在 PHP 中回显 /(斜线)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2549673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I echo a / (slash) in PHP?
提问by Howard Zoopaloopa
How do I echo a forwardslash /?
如何回显正斜杠/?
echo <?php echo $_SERVER['HTTP_HOST'] ?> . '/directory/';
回答by nickf
The way you echo a forward slash is like this:
你回显正斜杠的方式是这样的:
echo "/";
I think your problem is that you're opening/closing PHP tags inside what I assume is already a block of php. Change to this:
我认为您的问题是您正在打开/关闭我认为已经是一个 php 块的 PHP 标签。改成这样:
<?php
echo $_SERVER['HTTP_HOST'] . '/directory/';
回答by John Conde
echo $_SERVER['HTTP_HOST'] . '/directory/';
回答by waiwai933
You're putting in extra <?phptags, which you don't need.
您正在放入不需要的额外<?php标签。
<?php
// Insert other PHP code here
echo $_SERVER['HTTP_HOST'].'/directory/';
// Insert more PHP code here
?> <!-- You can put HTML here -->
回答by swt83
Ya, you've closed your PHP tag while still using PHP. Try this:
是的,您在使用 PHP 的同时关闭了 PHP 标签。尝试这个:
<?php echo $_SERVER['HTTP_HOST'] . '/directory/'; ?>
With regard to echoing a forward slash, no escape is necessary:
关于回显正斜杠,不需要转义:
<?php echo "/"; ?>

