【问题标题】:PHP While with hyphen add and lowercasePHP While 带有连字符加和小写
【发布时间】:2014-10-21 11:08:35
【问题描述】:

谁能看到我在使用小写字符串时做错了什么?

Preg_replace 有效,但是当我添加 stringtolower 时,它会中断消息。 " 意外的 'strtolower' (T_STRING),期待 ',' 或 ';'"

            <?php
            while($row10=mysql_fetch_array($result10))
            {
            echo "<a href=\"" . string strtolower (preg_replace('#[ -]+#', '-', $row10['english_navn'])); . ".php\"><div class=\"row\"><div class=\"large-3 columns\"><div class=\"b\"><br />" . $row10['chapter'] . "</div></div>";
            echo "<div class=\"large-9 columns\"><h2>" . $row10['english_navn'] .     "</h2></div></div></a>";
            }
            ?>

【问题讨论】:

  • 以这种方式回显 HTML 将会给您带来未来的问题。考虑通过关闭临时 ?&gt; 直接回显 HTML,渲染 HTML 并再次打开 &lt;?php

标签: php preg-replace lowercase


【解决方案1】:

你需要吗

string strtolower (...

或者你能把'字符串'拿出来吗?

 echo "<a href=\"" . strtolower (preg_replace('#[ -]+#', '-', $row10['english_navn'])) . ".php\"><div class=\"row\"><div class=\"large-3 columns\"><div class=\"b\"><br />" . $row10['chapter'] . "</div></div>";

【讨论】:

  • 仍然不正确。查看您的第二个代码块。在 strtolower 函数关闭的位置之后。
【解决方案2】:

为您修复了代码。下次我建议对字符串使用单引号,这样您就不必为 html 属性使用\"

<?php
while($row10=mysql_fetch_array($result10))
{
    echo "<a href=\"" . strtolower(preg_replace('#[ \-]+#', '-', $row10['english_navn'])) . ".php\"><div class=\"row\"><div class=\"large-3 columns\"><div class=\"b\"><br />" . $row10['chapter'] . "</div></div>";
    echo "<div class=\"large-9 columns\"><h2>" . $row10['english_navn'] . "</h2></div></div></a>";
}
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    • 2019-07-01
    • 2015-11-08
    • 2017-11-27
    相关资源
    最近更新 更多