0

拙いタイトルで申し訳ありません。次のコードがあるとします。

<?php  

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

where[style]は次の値を返します。 'bar','baz','apple'

どうすればこれを正しく取り除き、この奇妙な PHP 解析の代わりに html+css 標準にすることができますか?

「奇妙な」ことを明確にするために:これをブラウザで標準のHTMLページとして開くことはできません。それが私がやりたいことです。

4

3 に答える 3

0

「bar」、「baz」、「apple」は別の css クラスだと思います。これは foo- と連結します。つまり、foo-bar、foo-baz などです。そうであれば、このように各クラスを分解する必要があります。

<?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>
于 2013-06-12T14:52:20.637 に答える
0

あなたのコード:

<?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;
?>

それ以外の場合は、html + css 標準で記述できます。

<?php  
$css = 'foo-'.$data['style'];  
?>

<table>
  <tr>
    <td class="<?php echo $css; ?>">styled!</td>
  </tr>
</table>
于 2013-06-12T14:32:38.733 に答える