我如何连接html和php?

时间:2014-05-03 20:09:02

标签: php

我目前有这个:

    $output .= '
    <tr>
    <th style="text-align: left">'.(__("Item", "WSPSC")).'</th><th>'.(__("Quantity", "WSPSC")).'</th><th>'.(__("Price", "WSPSC")).'</th><th></th>
    </tr>';

但是我需要将 Item 替换成一段像:

的php
$output .= '
    <tr>
    <th style="text-align: left">'.(__("
     <?php if(ICL_LANGUAGE_CODE=='en'); ?>
         Item
     <?php elseif(ICL_LANGUAGE_CODE=='it'); ?>
        Products
     <?php endif; ?>
        ", "WSPSC")).'</th><th>'.(__("Quantity", "WSPSC")).'</th><th>'.(__("Price", "WSPSC")).'</th><th></th>
    </tr>';

我遇到的问题是这显然是错误的,但我无法理解html和php的正确连接

3 个答案:

答案 0 :(得分:1)

你不应该以这种方式使用它。看看这个伪代码:

$output .= '
<tr>
<th style="text-align: left">';


if (something...) {
   $output.= 'sss';
} 
elseif (something...) {
   $output.= 'ddd'; 
}

这就是你应该这样做的方式。

答案 1 :(得分:1)

如果我理解你需要这样的东西:

$output .= '
    <tr>
    <th style="text-align: left">'.
( 
  (ICL_LANGUAGE_CODE=='en')? 
    'Item': 
    ( (ICL_LANGUAGE_CODE=='it')? 'Products': '' ), 
  "WSPSC"
)
.'</th><th>'.(__("Quantity", "WSPSC")).'</th><th>'.(__("Price", "WSPSC")).'</th><th></th>
    </tr>';

答案 2 :(得分:0)

你的回复对我表示感谢,这很有效:

$output .= '
<tr>
<th style="text-align: left">';
if (ICL_LANGUAGE_CODE=='en') {
    $output .= (__("Item", "WSPSC"));
} elseif (ICL_LANGUAGE_CODE=='it') {
    $output .= (__("PRODOTTO", "WSPSC"));
}
$output .= '</th><th>'.(__("Quantity", "WSPSC")).'</th><th>'.(__("Price", "WSPSC")).'</th><th></th>
</tr>';