1

How would I get this to work?

$step = $_SERVER['PHP_SELF']. '?&step=';
echo "<form action=". $step ."2"><select>";

It's giving me a (Parse error: syntax error, unexpected '<') on the second line. Halp?

4

5 回答 5

4

转义字符串内的引号:

echo "<form action=\"${step}2\"><select>";

这将解决您的问题,但在将属性值放入 HTML 之前转义它可能是一个好主意:

echo "<form action=\"" . htmlspecialchars($step) . "2\"><select>";
于 2012-07-24T02:43:08.850 回答
3

The " after the 2 ends the string. Escape it or use single quotes.

$step = $_SERVER['PHP_SELF']. '?&step=';
echo "<form action=\"", $step , "2\"><select>";
于 2012-07-24T02:41:40.257 回答
2

Try escaping the double-quotes, or using a combination of double/singe:

echo "<form action=\"". $step ."2\"><select>";

or

echo '<form action="'. $step .'2"><select>';
于 2012-07-24T02:42:02.970 回答
2

Try actually paying attention to colour coding. Or use an editor that has colour-coding if yours doesn't.

echo '<form action="'.$step.'2"><select>';
于 2012-07-24T02:42:15.333 回答
1
$step = $_SERVER['PHP_SELF']. '?&step=';
echo "<form action=". $step .'"2"><select>';

或者

$step = $_SERVER['PHP_SELF']. '?&step=';
echo "<form action=". $step ."\"2\""><select>";
于 2012-07-24T02:44:35.007 回答