php获取html的价值(php getting value for html)

编程入门 行业动态 更新时间:2024-10-23 11:25:17
php获取html的价值(php getting value for html)

我有以下示例:

我在config \ resources.php中有一个值数组 - 例如:

<?php define('resrc', array( 'logo' => 'src/images/logo.png', 'bscss' => 'src/bootstrap.css', 'bsthcss' => 'src/bootstrap-theme.css', 'bsjs' => 'src/js/bootstrap.js', 'chset' => 'utf-8', 'jquery' => '/src/jquery/jquery_1.12.4_min.js', ) ); ?>

现在在结构\ head.php我有这样的事情:

<?php require('config/resources.php'); class Head { public static $head; public static function renderHeadTag() { $head = "<head>"; $head .= "<meta charset=".$resrc['chset'].">"; $head .= "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">"; $head .= "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"; $head .= "</head>"; return $head; } } ?>

但我仍然无法获得数组的值。 我做这样的事情已经有一段时间了。 任何人都可以暗示一下吗?

I have the following example:

I have an array of values in config\resources.php - eg.:

<?php define('resrc', array( 'logo' => 'src/images/logo.png', 'bscss' => 'src/bootstrap.css', 'bsthcss' => 'src/bootstrap-theme.css', 'bsjs' => 'src/js/bootstrap.js', 'chset' => 'utf-8', 'jquery' => '/src/jquery/jquery_1.12.4_min.js', ) ); ?>

Now in the structure\head.php I have something like this:

<?php require('config/resources.php'); class Head { public static $head; public static function renderHeadTag() { $head = "<head>"; $head .= "<meta charset=".$resrc['chset'].">"; $head .= "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">"; $head .= "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"; $head .= "</head>"; return $head; } } ?>

but I still can't get the value of the array. It is quite a while since i were doing something like this. Can anybody give a hint?

最满意答案

你正在使用常量数组

调用常量不得以美元符号为前缀

这一行:

$head .= "<meta charset=".$resrc['chset'].">";

应该如下:

$head .= "<meta charset=".resrc['chset'].">";

PS常量遵循一些命名约定,最好用(不一定要)用大写字母命名常量,例如RESRC

you are using a constants array

calling constants must not prefixed with dollar sign

this line :

$head .= "<meta charset=".$resrc['chset'].">";

should be as follows :

$head .= "<meta charset=".resrc['chset'].">";

P.S. constants following some naming convention , it's better (not must have) to name your constants in capital letters, RESRC for example

更多推荐

本文发布于:2023-04-29 09:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335905.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:价值   php   html

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!