PHP 解析错误!

发布于 2024-10-20 05:13:17 字数 477 浏览 7 评论 0原文

我试图找出这个错误的来源(我试图使用 PHP 输出一些 HTML)。

$newLI = "<li id = $row['\"id\"'] style=\"padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;\">";

这最终给了我:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /homepages/31/d346239161/htdocs/Bloominate/alpha/getProfileData.php on line 23

我无法弄清楚解析错误在哪里:(。

I'm trying to figure out where this error comes in (I'm trying to output some HTML using PHP).

$newLI = "<li id = $row['\"id\"'] style=\"padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;\">";

Which ends up giving me:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /homepages/31/d346239161/htdocs/Bloominate/alpha/getProfileData.php on line 23

I can't figure out where the parse error is :(.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

渡你暖光 2024-10-27 05:13:17

您需要将 $row['id'] 用大括号括起来,例如 {$row['id']}
尽管它应该用 HTML 属性的单引号引起来,但不需要其他转义: id='{$row['id']}'

所以一个完整的答案不使用字符串连接和双引号将是:

$newLI = "<li id='{$row['id']}' style='padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;'>";

You need to enclose $row['id'] in curly braces, like {$row['id']}
No other escaping is necessary on it, though it should be enclosed in single quotes for the HTML attribute: id='{$row['id']}'

So a complete answer using no string contatenation and double-quoting would be:

$newLI = "<li id='{$row['id']}' style='padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;'>";
︶葆Ⅱㄣ 2024-10-27 05:13:17

使用单引号和字符串连接可能更容易避免这些错误:

$newLI = '<li id="'.$row['id'].'" style="padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;">';

此外,您不必转义 HTML 代码的双引号。

It may be easier to avoid these errors by using single quotes and string concatenation:

$newLI = '<li id="'.$row['id'].'" style="padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;">';

Additionally you don't have to escape double quotes of the HTML code.

厌倦 2024-10-27 05:13:17

你的问题是 $row 本身。

// The following is okay, as it's inside a string. Constants are not looked for
// within strings, so no E_NOTICE occurs here
print "Hello $arr[fruit]";      // Hello apple

// With one exception: braces surrounding arrays within strings allows constants
/    / to be interpreted
print "Hello {$arr[fruit]}";    // Hello carrot
print "Hello {$arr['fruit']}";  // Hello apple

// This will not work, and will result in a parse error, such as:
// Parse error: parse error, expecting T_STRING' or T_VARIABLE' or T_NUM_STRING'
// This of course applies to using superglobals in strings as well
print "Hello $arr['fruit']";
print "Hello $_GET['foo']";

// Concatenation is another option
print "Hello " . $arr['fruit']; // Hello apple

请参阅 http://php.net/manual/en/language.types.array。 php 了解更多信息。

your problem is with $row itself.

// The following is okay, as it's inside a string. Constants are not looked for
// within strings, so no E_NOTICE occurs here
print "Hello $arr[fruit]";      // Hello apple

// With one exception: braces surrounding arrays within strings allows constants
/    / to be interpreted
print "Hello {$arr[fruit]}";    // Hello carrot
print "Hello {$arr['fruit']}";  // Hello apple

// This will not work, and will result in a parse error, such as:
// Parse error: parse error, expecting T_STRING' or T_VARIABLE' or T_NUM_STRING'
// This of course applies to using superglobals in strings as well
print "Hello $arr['fruit']";
print "Hello $_GET['foo']";

// Concatenation is another option
print "Hello " . $arr['fruit']; // Hello apple

see http://php.net/manual/en/language.types.array.php for more info.

眼角的笑意。 2024-10-27 05:13:17

实际的答案是:-

$newLI = '<li id = '.$row['id'].' style="padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;">';

希望有帮助。

The actual answer will be :-

$newLI = '<li id = '.$row['id'].' style="padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;">';

Hope it helps.

懒的傷心 2024-10-27 05:13:17

更改

$newLI = "<li id = $row['\"id\"'] style=\"padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;\">"

为:

$rowID = $row['id'];
$newLI = "<li id=$rowID style=\"padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;\">"

这是因为您引用了 $row['id']。

Change

$newLI = "<li id = $row['\"id\"'] style=\"padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;\">"

To:

$rowID = $row['id'];
$newLI = "<li id=$rowID style=\"padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;\">"

It's because you reference $row['id'].

忆伤 2024-10-27 05:13:17

为什么不保持干净和简单,例如:

<?php

$newLI = "<li id =".$row['id']." style=\"padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;\">";

?>

Why not keep it clean and simple like:

<?php

$newLI = "<li id =".$row['id']." style=\"padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;\">";

?>
迷乱花海 2024-10-27 05:13:17

试试这个

$newLI = "<li id = $row['id'] style='padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;'>";

try this

$newLI = "<li id = $row['id'] style='padding-right: 20px; display:inline; border-right: 1px gray solid; margin: 0px; color: white;'>";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文