2016-01-01 41 views
-3

我需要echo這一行,如何呼應複雜的HTML標籤

<?php 
echo '<input class="easyui-combobox" 
      name="language" 
      data-options=" 
        url:'get_clients.php', 
        method:'get', 
        valueField:'client_id', 
        textField:'client_name', 
        panelHeight:'auto'">'; 
?> 

但它顯示我此錯誤:

Parse error: syntax error, unexpected 'get_clients' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\testing\create_order.php on line 16

+0

提示:修復你的嵌套引號。逃脫它們。 –

+0

只需在關閉php之後編寫純html,而不是回顯它 – JimL

回答

2

你可能會認爲使用定界符語法複雜的文本或HTML玩:

語法如下:

$variableName = <<< identifier  //on one line declare var 
your complex html goes here   //on a new line write your complex text 
identifier; //close identifier 

在你的情況:

$inputElement = <<< INP 
<input class="easyui-combobox" 
       name="language" 
       data-options=" 
         url:'get_clients.php', 
         method:'get', 
         valueField:'client_id', 
         textField:'client_name', 
         panelHeight:'auto'"> 
INP; 

echo $inputElement ; 
+0

它的工作作爲魅力男人謝謝 – Karim

0

您需要使用反斜槓(\)逃避所有單引號,像這樣:

<?php 
    echo '<input class="easyui-combobox" 
       name="language" 
       data-options=" 
         url:\'get_clients.php\', 
         method:\'get\', 
         valueField:\'client_id\', 
         textField:\'client_name\', 
         panelHeight:\'auto\'">'; 

?> 
+0

這就是我正在建議的。或者只是不要在字符串中使用單引號......而是換成雙引號(或反向)。 –

+0

@ josh.thomson但即使有雙引號,OP也必須使用反斜槓來轉義所有中間雙引號。 –

+0

是的,它的工作太多了,非常感謝您的幫助 – Karim

2

而不是使用echo,您可以簡化Ÿ逃回PHP的文字輸出模式:

<?php 
if ($something) { 
?> 
<input class="easyui-combobox" 
     name="language" 
     data-options=" 
       url:'get_clients.php', 
       method:'get', 
       valueField:'client_id', 
       textField:'client_name', 
       panelHeight:'auto'"> 

<?php } 
+0

這個回聲我必須在IF語句中添加,所以我不能逃脫php – Karim

+0

你可以在'if'語句中做到這一點,我更新了答案 – Barmar