以下代码中的错误是什么: 我收到的错误如下:
PHP Parse错误:语法错误,第38行的pdf_test_question_paper.php中的意外T_STRING
$header_html = '<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
<td><img src="http://www.example.com/upload_media/coaching/logo/display/".$coaching_details['coach_inst_logo_name']." width="198"></td>
<td>
<h2 style="margin:0;padding:0;">Jumbo Exam Easing your Exam Preparation</h2>
<span>$coaching_address</span>
</td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>';
非常感谢任何帮助。
答案 0 :(得分:2)
当您将字符串换成单引号时,您使用的是文字值。这意味着永远不会评估$coaching_address
。您应该使用heredoc代替此数量的代码:
$header_html = <<<EOD
<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
<td><img src="http://www.xyz.com/upload_media/coaching/logo/display/$coaching_details['coach_inst_logo_name']" width="198"></td>
<td>
<h2 style="margin:0;padding:0;">Zimma Exam Easing your Exam Preparation</h2>
<span>$coaching_address</span>
</td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>
EOD;
答案 1 :(得分:0)
请在字符串concaternation的情况下使用正确的引用:
$header_html = '<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
<td><img src="http://www.example.com/upload_media/coaching/logo/display/'.$coaching_details['coach_inst_logo_name'].' width="198"></td>
<td>
<h2 style="margin:0;padding:0;">Jumbo Easing your Exam Preparation</h2>
<span>'.$coaching_address.'</span>
</td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>';
答案 2 :(得分:0)
您使用单引号启动字符串,但是您尝试使用双引号来突破引号。
正确的代码是:
$header_html = '<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
<td><img src="http://www.example.com/upload_media/coaching/logo/display/'.$coaching_details['coach_inst_logo_name'].' width="198"></td>
<td>
<h2 style="margin:0;padding:0;">Jumbo Easing your Exam Preparation</h2>
<span>'.$coaching_address.'</span>
</td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>';