Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 制作一个与包含url和图像扩展名的字符串匹配的正则表达式_Php_Regex - Fatal编程技术网

Php 制作一个与包含url和图像扩展名的字符串匹配的正则表达式

Php 制作一个与包含url和图像扩展名的字符串匹配的正则表达式,php,regex,Php,Regex,我不擅长正则表达式,尽管如此,我正在尝试制作一个正则表达式,它允许url的所有图片类型如下: $regex = '~mydomain.ide.com/polopoly_fs/([a-z0-9\\.\\_\\-]+(\\.gif|\\.png|\\.jpe?g))~i'; /** * Get the Images * @param unknown $html */ function getImages($html) { echo "Hello from getImages <b

我不擅长正则表达式,尽管如此,我正在尝试制作一个正则表达式,它允许url的所有图片类型如下:

$regex = '~mydomain.ide.com/polopoly_fs/([a-z0-9\\.\\_\\-]+(\\.gif|\\.png|\\.jpe?g))~i'; 
/**
 * Get the Images
 * @param unknown $html
 */
function getImages($html) {
  echo "Hello from getImages <br/>";

  $matches = array();

  $regex = '~http://mySite.ide.com/([a-z0-9\\.\\_\\-]+(\\.gif|\\.png|\\.jpe?g))~i'; //include all formats

  preg_match_all($regex2, $html, $matches);
  foreach ($matches[1] as $img) {
    saveImg($img);
  }
}
//包括所有格式

其目的是获取具有如下功能的web图片:

$regex = '~mydomain.ide.com/polopoly_fs/([a-z0-9\\.\\_\\-]+(\\.gif|\\.png|\\.jpe?g))~i'; 
/**
 * Get the Images
 * @param unknown $html
 */
function getImages($html) {
  echo "Hello from getImages <br/>";

  $matches = array();

  $regex = '~http://mySite.ide.com/([a-z0-9\\.\\_\\-]+(\\.gif|\\.png|\\.jpe?g))~i'; //include all formats

  preg_match_all($regex2, $html, $matches);
  foreach ($matches[1] as $img) {
    saveImg($img);
  }
}
/**
*获取图像
*@param未知$html
*/
函数getImages($html){
回显“来自getImages的你好
”; $matches=array(); $regex='1~http://mySite.ide.com/([a-z0-9\\.\\\\\\\\\\\-]+(\\.gif\\.png\\.jpe?g))~i';//包括所有格式 preg_match_all($regex2,$html,$matches); foreach($img与[1]匹配){ 储蓄人民币($img); } }
但我需要一个正则表达式,它使用一个具有以下结构的url:

有人能帮忙吗


谢谢

像这样的东西就足够了

/(.*.com\/[a-z_-]+\/[0-9\.a-z!]+\/[a-z0-9_-]+\.(gif|jpg|jpeg|png))/i
下面是PHP代码

<?php

$s = "http://mydomain.ide.com/polopoly_fs/1.573651!imageManager/3188890795.jpg";

preg_match("/(.*.com\/[a-z_-]+\/[0-9\.a-z!]+\/[a-z0-9_-]+\.(gif|jpg|jpeg|png))/i", $s, $arrMatches);

echo print_r($arrMatches[0], true);

好了,现在这有点清楚了,我可以多帮点忙

如果我理解正确的话,你想要的是在整个html中搜索完全符合条件的图像URL来保存它们,而不管它们的名称或位置

function getImages($html) {
  echo "Hello from getImages <br/>";

  $matches = array();

  $regex = '~http://.*/[a-z0-9._-]+(?:\.gif|\.png|\.jpe?g)~i'; //include all formats

  preg_match_all($regex, $html, $matches);
  foreach ($matches as $img) {
    saveImg($img[0]);
  }
}
函数getImages($html){ 回显“来自getImages的你好
”; $matches=array(); $regex='~http://./[a-z0-9.\-]+(?:\.gif\.png\.jpe?g)~i';//包括所有格式 preg_match_all($regex,$html,$matches); foreach($匹配为$img){ saveImg($img[0]); } }
您不必在这里捕获任何内容,匹配将足够,需要转义的唯一字符是。匹配.gif.png等中的小圆点


如果我误解了,请随时发表评论,我会修改

您使用它的目的是什么?也许有比使用正则表达式更好的方法。