不确定下面的代码为什么不起作用。有什么想法吗?
<table width="567"
$text = preg_replace('/<table width=["\']\s*\d+\s*(px|%)\s*["\']/', '<table width="100%"', $text);
尝试使用此模式:
/<table ([^>]*?)width=["\']\s?\d+\s?(px|%)?\s*["\']/
替换$1
将保留任何其他属性(请参阅(.*?)
捕获组):
$text = preg_replace('/<table (.*?)width=["\']\s?\d+\s?(px|%)?\s*["\']/', '<table $1width="100%"', $text);