如何使用PHP动态添加CSS代码?

时间:2017-11-22 14:37:23

标签: php css

我有这个样本:

代码PHP

<?php Zend_Debug::dump($_helper->productAttribute($_product, $_product->getDescription(), 'description')); exit; ?>

返回此字符串

string(345) "<p>With glossy, raven-black frames, the <strong>Coleman</strong> frames command attention. With a slightly wider frame, narrow bridge, and more rounded line, you&rsquo;ll feel stylish and modern. Their bold, elegant, raven-black color is every bit the classic look. But their high style and lightweight feel hit just the right modern note.</p>

我想操纵这个字符串,所以要具有以下形式:

string(345) "<p>With glossy, raven-black frames, the <strong style="font-size: echo $myvar; ">Coleman</strong> frames command attention. With a slightly wider frame, narrow bridge, and more rounded line, you&rsquo;ll feel stylish and modern. Their bold, elegant, raven-black color is every bit the classic look. But their high style and lightweight feel hit just the right modern note.</p>

基本上我想为我的php字符串添加css样式。

我该如何动态地执行此操作?

提前谢谢!

1 个答案:

答案 0 :(得分:0)

让我们假设您将字符串存储在$ str变量中。然后:

str_replace("<strong>", "<strong style='font-size: " . $myvar . "'>", $str);