This article mainly introduces PHP to delete the HTML code in the wide-height style of the method, involving PHP for HTML code of regular matching, replacement and other operational skills, the need for friends can refer to the following
The example in this article describes how PHP is deleting the wide-height style in HTML code. Share to everyone for your reference, as follows:
Because of the need for work, you need to collect HTML and save the HTML content to the database. To avoid impact usage, the wide-height style needs to be removed. The width, height, etc. in the case and P.
However, the collection of HTML, the style of writing each has a different, such as case, the middle of a space and so on.
As a result, the following method is written using PHP, which filters out these wonderful patterns.
The code is as follows:
<?php/** * Clear the wide height style * @param string $content contents * @return string */function clear_wh ($content) { $config = array (' Widt H ', ' height '); foreach ($config as $v) { $content = preg_replace ('/'. $v. ' \s*=\s*\d+\s*/i ', ', $content); $content = preg_replace ('/'. $v. ' \s*=\s*.+?[' \ ']/i ', ', $content); $content = preg_replace ('/'. $v. ' \s*:\s*\d+\s*px\s*;? /I ', ', $content); } return $content;}? >
Demonstrate:
<?php$html = <<
Output: