LoginSignup
5
6

More than 5 years have passed since last update.

srcタグ抽出の正規表現(php)

Posted at

phpでsrc=のURL先を抽出する正規表現

$pettern1    = "/<img.*?src[[:space:]]{0,}=[[:space:]]{0,}[\"']{0,}(.*?[^\"'>[:space:]]{0,}.*?[^\"'>[:space:]]{0,}.*?)[\"']{0,}[[:space:]]{0,}.*?>/is";
$pettern2    = "/<a.*?href[[:space:]]{0,}=[[:space:]]{0,}[\"']{0,}(.*?[^\"'>[:space:]]{0,}.*?[^\"'>[:space:]]{0,}.*?)[\"']{0,}[[:space:]]{0,}.*?>(.*?)<\/(.+?)/is";
$pettern3    = "/<script.*?src[[:space:]]{0,}=[[:space:]]{0,}[\"']{0,}(.*?[^\"'>[:space:]]{0,}.*?[^\"'>[:space:]]{0,}.*?)[\"']{0,}[[:space:]]{0,}.*?>/is";
$pettern4    = "/<area.*?href[[:space:]]{0,}=[[:space:]]{0,}[\"']{0,}(.*?[^\"'>[:space:]]{0,}.*?[^\"'>[:space:]]{0,}.*?)[\"']{0,}[[:space:]]{0,}.*?>/is";
$pettern5    = "/<link.*?href[[:space:]]{0,}=[[:space:]]{0,}[\"']{0,}(.*?[^\"'>[:space:]]{0,}.*?[^\"'>[:space:]]{0,}.*?)[\"']{0,}[[:space:]]{0,}.*?>/is";
$pettern6    = "/@import.*?u?r?l?\(?[\"']{0,}(.*?[^\"';\)]{0,}.*?[^\"';\)]{0,}.*?)[\"']{0,}\)?;?/is";
$pettern7    = "/background\-image[[:space:]]{0,}:[[:space:]]{0,}url\([\"']{0,}(.*?[^;\)\"'>]{0,}.*?[^;\)\"'>]{0,}.*?)[\"']{0,}\);?/is";
$pettern8    = "/background[[:space:]]{0,}=[[:space:]]{0,}[\"']{0,}(.*?[^;\)\"'>]{0,}.*?[^;\)\"'>]{0,}.*?)[\"']{0,}/is";
$pettern9    = "/background[[:space:]]{0,}:[[:space:]]{0,}url\([\"']{0,}(.*?[^;\)\"'>]{0,}.*?[^;\)\"'>]{0,}.*?)[\"']{0,}\)/is";
5
6
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6