标准化PHP+;CSS不使用字符串解析

标准化PHP+;CSS不使用字符串解析,php,html,css,Php,Html,Css,我为这个糟糕的标题道歉。给定以下代码: <?php $css = 'foo-'.$data['style']; $html= "<table><tr><td class='{$css}>styled! /> </tr> </table>; ?> 您的代码: <?php $css = 'foo-'.$data['style']; $html= "<table>&l

我为这个糟糕的标题道歉。给定以下代码:

<?php  

    $css = 'foo-'.$data['style'];  
    $html= "<table><tr><td class='{$css}>styled! /> </tr>  </table>;
?>

您的代码:

<?php  
$css = 'foo-'.$data['style'];  
$html= "<table><tr><td class='{$css}>styled! /> </tr>  </table>;
?>

我认为‘bar’、‘baz’、‘apple’是独立的css类。它将与foo-结合。我的意思是foobar,foobaz等等。如果是这样的话,那么你必须像这样分解每个类

<?php
 $css_arr = explode(',',$data['style']);
$css_all_class = implode(' foo-',$css_arr);
$css_all_class  = "foo-".$css_all_class ;
//$css_all_class = " foo-bar foo-baz foo-apple"
?>

<table>
   <tr>
      <td class="<?php echo $css_all_class; ?>">styled!</td>
   </tr>
</table>


你不是缺少一些引号吗?有一个数组吗?
$data['style']
我不明白这个问题。这种奇怪的PHP解析是如何实现的?你只是在用一个变量作为填充物。@DanLee这很奇怪,因为如果我在浏览器中打开它,它不是独立的。只要把你的标记放在标记之外就行了。是xml处理指令的格式,因此如果您有与xml兼容的doctype,那么浏览器应该忽略它不理解的所有PI。我不确定,请在您的本地计算机上检查。您想要这样的东西吗。“时尚!”。如果是的话,它应该可以工作。
$style = "foo-".$data["style"];
?>
<table><tr><td class='<?= $style ?>' /> </tr>  </table>
<?php  
$css = 'foo-'.$data['style'];  
$html= "<table><tr><td class='{$css}>styled! /> </tr>  </table>;
?>
<?php  
$css = 'foo-'.$data['style'];  
$html= "<table><tr><td class=".$css.">styled! </td></tr></table>";
echo $html;
?>
<?php  
$css = 'foo-'.$data['style'];  
?>

<table>
  <tr>
    <td class="<?php echo $css; ?>">styled!</td>
  </tr>
</table>
<?php
 $css_arr = explode(',',$data['style']);
$css_all_class = implode(' foo-',$css_arr);
$css_all_class  = "foo-".$css_all_class ;
//$css_all_class = " foo-bar foo-baz foo-apple"
?>

<table>
   <tr>
      <td class="<?php echo $css_all_class; ?>">styled!</td>
   </tr>
</table>