[英]How to remove warning in echoing a string constant in PHP
I declared a string constant named LABTITLE. 我声明了一个名为LABTITLE的字符串常量。 When I tried to echo it in the title tag and run the code, the title of the webpage shows a warning. 当我尝试在title标签中回显它并运行代码时,网页的标题显示警告。 Is there something wrong with my code? 我的代码有问题吗?
Our professor specifically instructed to print the Title in this way. 我们的教授特别指示以这种方式打印标题。
The Title tag: 标题标签:
<title>
<?php
echo constant("LABTITLE");
?>
</title>
The PHP code: PHP代码:
<?php
define("LABTITLE", "Laboratory Activity No. 2");
?>
Then whenever I run, this shows in the Title tab: 然后,每当我运行时,它就会显示在“标题”选项卡中:
Warning : constant(): Couldn't find constant LABTITLE in C:\\xampp\\htdocs\\Lab2\\index.php on line 12 警告 :constant():在第12行的C:\\ xampp \\ htdocs \\ Lab2 \\ index.php中找不到常量LABTITLE
Define Your constant first then you can get value. 首先定义您的常数,然后您就可以获取价值。 looks like you are using constant value before you define. 看起来您在定义之前使用的是恒定值。
<?php
define("LABTITLE", "Laboratory Activity No. 2");
?>
<title>
<?php
echo constant("LABTITLE");
?>
</title>
Instead you could directly use 相反,您可以直接使用
<title>
<?php
echo LABTITLE;
?>
</title>
given following is included. 包括以下内容。
<?php
define("LABTITLE", "Laboratory Activity No. 2");
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.