Use the regular expression method in PHP to remove HTML's wide-height style method

Source: Internet
Author: User
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:


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.