這是原來的代碼亮/添加背景色,以PHP結果
<?php echo $shippingDescription ?>
這是我嘗試
<span style="font-family:Arial, Helvetica, sans-serif;<?php if($shippingDescription=Free Shipping)echo "color:red"?>"><?php echo $shippingDescription; ?></span>
代碼基本上我只是希望它的背景色添加到文本/結果,如果它是免費送貨
你應該學會PHP語法。首先,如果你想比較一個變量和一個字符串,它必須是一個代表[string](http://php.net/manual/en/language.types.string.php)的值。在PHP中,字符串可以是單引號或雙引號。其次,'$ shippingDescription ='會將''作爲'$ shippingDescription'變量的值,而不是進行比較。對於[比較](http://php.net/manual/en/language.operators.comparison.php),使用'==='。所以它應該看起來像這樣:'如果($ shippingDescription ==='免費送貨')''。 –
MarthyM