簡體   English   中英

我可以在 PHP 的 echo 語句中使用 strtolower() 之類的函數嗎?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM