Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用正则表达式固定某些元素的宽度_Php_Html_Css_Regex - Fatal编程技术网

Php 用正则表达式固定某些元素的宽度

Php 用正则表达式固定某些元素的宽度,php,html,css,regex,Php,Html,Css,Regex,我在网站上使用tinyMCE,我通常会将Word tourism产品粘贴到其中,这会创建具有各种宽度的特定DIV,而我的主DIV(也包含tinyMCE的)的宽度约为550px 我想使用正则表达式将我的主div中所有可能元素的宽度减少到550px,因为除了我以外的其他人也使用页面编辑器,他不知道如何手动修改word创建元素的宽度。使用php,您可以预先替换维度: preg_match('"@[";\s]width\s*:\s*([0-9]{3,})px@', $html, $matches);

我在网站上使用tinyMCE,我通常会将Word tourism产品粘贴到其中,这会创建具有各种宽度的特定DIV,而我的主DIV(也包含tinyMCE的
)的宽度约为550px


我想使用正则表达式将我的主div中所有可能元素的宽度减少到550px,因为除了我以外的其他人也使用页面编辑器,他不知道如何手动修改word创建元素的宽度。

使用php,您可以预先替换维度:

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);
    }
}
记住,尽管

宽度可以用ems或%表示 填充和边框添加到标注中 漂浮物可以把它们放在一起


。。。出于这些原因,我建议您最好在主DIV中添加
overflow:hidden

您是指MS Word吗?你能举一个你想修改的文本的例子吗?那么你想把所有元素的大小调整到550像素或者550个一块?您是在创建之后还是之前尝试修改图元?DIV有ID、名字或类似的东西吗?页面是如何生成的,为什么不能在创建之前修改div大小?请发布示例,因为这个问题在当前状态下无法回答;这是否意味着你不在乎正则表达式的作用在哪里(比如在tinymce中还是在后端)?嗨,我刚刚添加了“PHP”标记,我的帖子似乎被其他人修改了。首先,tinymce中插入了一个MS Word页面,创建了一个600px的DIV,但我的主DIV,包含tinymce,是550px,我希望该div中的所有内容都不超过该大小。您是否有示例文档,以便我查看word代码的格式?