我在网站上使用 tinyMCE,我通常会在其中粘贴 Word 旅游优惠,这会创建具有各种宽度的某些 DIV,而我的主 DIV(其中还包含 tinyMCE 的 <textarea>
)约为 550px宽度。
我想使用正则表达式来将我的主 div 中所有可能元素的宽度减小到 550px - 因为除我之外的其他人也使用页面编辑器,他不知道如何手动修改字的宽度-创建元素。
最佳答案
使用 php 你可以 preg_replace 维度:
preg_match('"@[";\s]width\s*:\s*([0-9]{3,})px@', $html, $matches);
foreach($matches as $match)
{
// if > 550 then make it 550
if((int)$match[1] > 550)
{
$new = str_replace((int)$match[1], '550', $match[0]);
$html = str_replace($match[0], $new, $html);
}
}
请记住……
宽度也可以是 em 或 % 填充和边框添加到尺寸 漂浮的东西可以把它们并排放置
...出于这些原因,我建议您最好将 overflow:hidden
添加到您的主 DIV
关于php - 使用正则表达式固定某些元素的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7221562/