Home  >  Article  >  Backend Development  >  Summary of php regular expression methods to obtain image url

Summary of php regular expression methods to obtain image url

WBOY
WBOYOriginal
2016-07-25 08:52:041298browse
  1. header("Content-type:text/html;charset=utf-8");
  2. $str = '

    Beauty

    ';
  3. $pattern = "/[img|IMG].*?src=['|"](.*?(?:[.gif|.jpg] ))['|"].*?[/]?>/";
  4. preg_match_all($pattern,$str,$match);
  5. echo "
    ";
  6. print_r($match);
  7. ?>
Copy the code

Attached, a summary of regular expressions for filtering html tags, attributes, etc. in PHP.

  1. function DeleteHtml($str)
  2. {
  3. $str = trim($str);
  4. $str = strip_tags($str,"");
  5. $str = ereg_replace("t","", $str);
  6. $str = ereg_replace("rn","",$str);
  7. $str = ereg_replace("r","",$str);
  8. $str = ereg_replace("n","" ,$str);
  9. $str = ereg_replace(" "," ",$str);
  10. return trim($str);
  11. }
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn