Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.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 调整HTML对象大小的正则表达式_Php_Html_Regex_Resize_Size - Fatal编程技术网

Php 调整HTML对象大小的正则表达式

Php 调整HTML对象大小的正则表达式,php,html,regex,resize,size,Php,Html,Regex,Resize,Size,我完全没有使用正则表达式的经验,所以遇到了一个小问题。 我需要将所有height=“*”和width=“*”-html标记替换为height=“auto”和width=“auto” 我可以用什么正则表达式在PHP中实现这一点? 谢谢 请注意,这仅适用于文字星号字符。对于通配符,应在更新后使用正则表达式 这不需要正则表达式,只需要两个str\u replace() 更新 不过,您可以使用正则表达式。它需要更多的资源,但可以添加一些基本检查(例如height=“*”不在元素内时不会更改): preg

我完全没有使用正则表达式的经验,所以遇到了一个小问题。 我需要将所有
height=“*”
width=“*”
-html标记替换为
height=“auto”
width=“auto”

我可以用什么正则表达式在PHP中实现这一点?
谢谢

请注意,这仅适用于文字星号字符。对于通配符,应在更新后使用正则表达式

这不需要正则表达式,只需要两个
str\u replace()

更新

不过,您可以使用正则表达式。它需要更多的资源,但可以添加一些基本检查(例如
height=“*”
不在元素内时不会更改):

preg_replace('/(]+(高度|宽度)=)“[^”]*“/i',“$1”auto“,$html);

我不知道您为什么要这样做,但添加样式不是更容易吗?*{height:auto;width:auto}你没有经验这一事实不会让事情变得更好。@Emil编辑。我添加了一些例子。我很确定Emil问题中的
*
是通配符,而不是字面上的星号…@Tim你可能是对的。让我们等到他回答。-在这种情况下,显然你可以用
\*
替换
[^]*
。我不知道str_replace使用通配符!为什么这没有记录在任何地方。。?谢谢!:)@埃米尔:不,它不起作用。我只是误解了你的问题:)你必须在我的回答中使用正则表达式模式。
$html = str_replace (' height="*"', ' height="auto"', $html);
$html = str_replace (' width="*"', ' width="auto"', $html);
preg_replace ('/(<[^>]+ (height|width)=)"[^"]*"/i', '$1"auto"', $html);