[英]Can I use a function such as strtolower() in the echo statement in PHP?
我试图在 echo 语句中将变量名称转换为全部小写。 例如:
$categories = array('1'=>'Holiday')
foreach ($categories as $categoryId => $category) {
echo "<div class=\"container\"> <a href=\"category.php?categoryId=$categoryId\">
<img src=\"images/categories/strtolower($category).jpg\" alt=\"holiday turkey\" class=\"image\">
<div class=\"overlay\"> <div class=\"text\">$category</div> </div> </a> </div> ";}
我想把变量名全部转换成小写,这样我就可以得到图片了。 我尝试将图像名称更改为 Holiday.jpg 但我想知道这是否可行...
先感谢您!
$categories = array('1'=>'Holiday')
foreach ($categories as $categoryId => $category) {
echo "<div class='container'><a href='category.php?categoryId=$categoryId'>
<img src='images/categories/".strtolower($category).".jpg' alt='holiday turkey' class='image'>
<div class='overlay'> <div class='text'>$category</div> </div> </a> </div>";
}
是的,你可以这样做:
foreach ($categories as $categoryId => $category) {
echo "<div class=\"container\"> <a href=\"category.php?categoryId=$categoryId\">
<img src=\"images/categories/" . strtolower($category) . ".jpg\" alt=\"holiday turkey\" class=\"image\">
<div class=\"overlay\"> <div class=\"text\">$category</div> </div> </a> </div> ";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.