0

我一直在与 meeplace 合作,我遇到了关于代码中的语法错误的问题。它在广告管理页面中:

echo "<option value='0'>AM</option>";
echo "<option value='12' ".$select.">PM</option>";

echo " </select></td>\r\n </tr>\r\n \r\n <tr>\r\n <td align=\"right\">Total Views Allowed:</td>\r\n <td><input type=\"text\" id=\"ad_total_views\" style=\"width:50px;\" value=\"\" disabled=\"disabled\" /> <label><input type=\"checkbox\" checked=\"checked\" onclick=\"if(this.checked==true){$('#ad_total_views').val('');$('#ad_total_views').attr('disabled','disabled');}else{$('#ad_total_views').val('');$('#ad_total_views').removeAttr('disabled');$('#ad_total_views').focus()}\" />Unlimited</label></td>\r\n </tr>\r\n \r\n <tr>\r\n <td align=\"right\">Total Clicks Allowed:</td>\r\n <td><input type=\"text\" id=\"ad_total_clicks\" style=\"width:50px;\" value=\"\" disabled=\"disabled\" /> <label><input type=\"checkbox\" checked=\"checked\" onclick=\"if(this.checked==true){$('#ad_total_clicks').val('');$('#ad_total_clicks').attr('disabled','disabled');}else{$('#ad_total_clicks').val('');$('#ad_total_clicks').removeAttr('disabled');$('#ad_total_clicks').focus()}\" />Unlimited</label></td>\r\n </tr>\r\n </table></td>\r\n </tr>\r\n <tr bgcolor=\"#FFFFFF\">\r\n <td class=\"td_th\" align=\"center\">Smarty Code (Developer)</td>\r\n <td>{\$ads->getAdCode(<span id=\"smartycode\">1</span>)}</td>\r\n </tr>\r\n <tr bgcolor=\"#FFFFFF\">\r\n <td class=\"td_th\" align=\"center\">&nbsp;</td>\r\n <td><input type=\"button\" value=\"Create New Campaign\" onclick=\"new_ad()\" /></td>\r\n </tr>\r\n </TBODY></TABLE>\r\n<br />\r\n\r\n<TABLE cellSpacing=1 cellPadding=4 width=\"100%\" border=0>\r\n <TBODY>\r\n <TR class=\"td_title\">\r\n <TD colSpan=7>Ad Campaigns</TD></TR>\r\n <TR bgColor=#ffffff>\r\n \r\n <TD width=\"10%\" align=\"center\" class=\"td_th\">&nbsp;</TD>\r\n <TD width=\"4%\" align=\"center\" class=\"td_th\">ID</TD>\r\n <TD width=\"29%\" align=\"center\" class=\"td_th\">Campaign Name</TD>\r\n <TD width=\"12%\" align=\"center\" class=\"td_th\">Start Date</TD>\r\n <TD width=\"11%\" align=\"center\" class=\"td_th\">End Date</TD>\r\n <TD width=\"17%\" align=\"center\" class=\"td_th\">Viewed / Views Allowed</TD>\r\n <TD width=\"17%\" align=\"center\" class=\"td_th\">Clicked / Clicks Allowed</TD>\r\n </TR>\r\n ";

我不太确定出了什么问题,错误出现在上面的第三行代码中。

Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$' in /mgt/body/ad_list.php on line 185

如果其他人遇到过这个问题或知道一个简单的答案来解决这个问题,那就太好了。我已经尝试了一些事情,比如让它不止一条线,但没有运气!:秒

更新

我设法将问题缩小到这一点:

     <label><input type=\"checkbox\" checked=\"checked\" onclick=\"if(this.checked==true){$('#ad_total_views').val('');$('#ad_total_views').attr('disabled','disabled');}else{$('#ad_total_views').val('');$('#ad_total_views').removeAttr('disabled');$('#ad_total_views').focus()}\" />Unlimited</label></td>\r\n 
4

2 回答 2

2

这是很久以来看到的一个疯狂echo的..我建议你使用Heredoc

例子

$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;

echo $str ;

回到你的脚本

<?php
$select ="test";
echo "<option value='0'>AM</option>";
echo "<option value='12' " . $select . ">PM</option>";
echo <<<DATA

</select>
</td>

</tr>

<tr>

    <td align="right">Total Views Allowed:</td>
    <td><input type="text" id="ad_total_views" style=""
        "width:50px;" value="" disabled="disabled" /> <label><input
            type="checkbox" checked="checked" onclick="if(this.checked==true){\$ ('#ad_total_views') . val ( '' );$

('#ad_total_views') . attr ( 'disabled', 'disabled' );
}else{\$('#ad_total_views').val('');$('#ad_total_views').removeAttr('disabled');\$('#ad_total_views').focus()}" />Unlimited</label></td>
</tr>

<tr>

    <td align="right">Total Clicks Allowed:</td>
    <td><input type="text" id="ad_total_clicks" style=""
        "width:50px;" value="" disabled="disabled" /> <label><input
            type="checkbox" checked="checked" onclick="if(this.checked==true){\$( '#ad_total_clicks').val('');$('#ad_total_clicks').attr('disabled','disabled');
}else{\$('#ad_total_clicks').val('');\$('#ad_total_clicks').removeAttr('disabled');\$('#ad_total_clicks').focus()}" />Unlimited</label></td>
</tr>

</table>
</td>

</tr>

<tr bgcolor="#FFFFFF">

    <td class="td_th" align="center">Smarty Code (Developer)</td>
    <td>{\$ads->getAdCode(<span id="smartycode">1</span>)}
    </td>
</tr>

<tr bgcolor="#FFFFFF">

    <td class="td_th" align="center">&nbsp;</td>
    <td><input type="button" value="Create New Campaign" onclick="new_ad()" /></td>
</tr>

</TBODY>
</TABLE>

<br />

<TABLE cellSpacing=1 cellPadding=4 width="100%"  border=0>

    <TBODY>

        <TR class="td_title">

            <TD colSpan=7>Ad Campaigns</TD>
        </TR>

        <TR bgColor=#ffffff>

            <TD width="10%" align="center" class="td_th">&nbsp;</TD>
            <TD width="4%" align="center" class="td_th">ID</TD>
            <TD width="29%" align="center" class="td_th">Campaign Name</TD>
            <TD width="12%" align="center" class="td_th">Start Date</TD>
            <TD width="11%" align="center" class="td_th">End Date</TD>
            <TD width="17%" align="center" class="td_th">Viewed / Views
                Allowed</TD>
            <TD width="17%" align="center" class="td_th">Clicked / Clicks
                Allowed</TD>
        </TR>

DATA;

?>

演示:http ://codepad.viper-7.com/3Scnp4

于 2012-04-22T19:36:29.343 回答
0

试试这个:

echo ' </select></td>'."\r\n".' </tr>'."\r\n".' '."\r\n".' <tr>'."\r\n".' <td align="right">Total Views Allowed:</td>'."\r\n".' <td><input type="text" id="ad_total_views" style="width:50px;" value="" disabled="disabled" /> <label><input type="checkbox" checked="checked" onclick="if(this.checked==true){$(\'#ad_total_views\').val(\'\');$(\'#ad_total_views\').attr(\'disabled\',\'disabled\');}else{$(\'#ad_total_views\').val(\'\');$(\'#ad_total_views\').removeAttr(\'disabled\');$(\'#ad_total_views\').focus()}" />Unlimited</label></td>'."\r\n".' </tr>'."\r\n".' '."\r\n".' <tr>'."\r\n".' <td align="right">Total Clicks Allowed:</td>'."\r\n".' <td><input type="text" id="ad_total_clicks" style="width:50px;" value="" disabled="disabled" /> <label><input type="checkbox" checked="checked" onclick="if(this.checked==true){$(\'#ad_total_clicks\').val(\'\');$(\'#ad_total_clicks\').attr(\'disabled\',\'disabled\');}else{$(\'#ad_total_clicks\').val(\'\');$(\'#ad_total_clicks\').removeAttr(\'disabled\');$(\'#ad_total_clicks\').focus()}" />Unlimited</label></td>'."\r\n".' </tr>'."\r\n".' </table></td>'."\r\n".' </tr>'."\r\n".' <tr bgcolor="#FFFFFF">'."\r\n".' <td class="td_th" align="center">Smarty Code (Developer)</td>'."\r\n".' <td>{\$ads->getAdCode(<span id="smartycode">1</span>)}</td>'."\r\n".' </tr>'."\r\n".' <tr bgcolor="#FFFFFF">'."\r\n".' <td class="td_th" align="center">&nbsp;</td>'."\r\n".' <td><input type="button" value="Create New Campaign" onclick="new_ad()" /></td>'."\r\n".' </tr>'."\r\n".' </TBODY></TABLE>'."\r\n".'<br />'."\r\n".''."\r\n".'<TABLE cellSpacing=1 cellPadding=4 width="100%" border=0>'."\r\n".' <TBODY>'."\r\n".' <TR class="td_title">'."\r\n".' <TD colSpan=7>Ad Campaigns</TD></TR>'."\r\n".' <TR bgColor=#ffffff>'."\r\n".' '."\r\n".' <TD width="10%" align="center" class="td_th">&nbsp;</TD>'."\r\n".' <TD width="4%" align="center" class="td_th">ID</TD>'."\r\n".' <TD width="29%" align="center" class="td_th">Campaign Name</TD>'."\r\n".' <TD width="12%" align="center" class="td_th">Start Date</TD>'."\r\n".' <TD width="11%" align="center" class="td_th">End Date</TD>'."\r\n".' <TD width="17%" align="center" class="td_th">Viewed / Views Allowed</TD>'."\r\n".' <TD width="17%" align="center" class="td_th">Clicked / Clicks Allowed</TD>'."\r\n".' </TR>'."\r\n".' ';

PHP 可能会因为字符串中的 $ 而感到困惑,因为它是一个双引号字符串,并且$被解析为该字符串内的变量开始。

于 2012-04-22T19:34:15.897 回答