我已经有了这段代码
但为此它会产生类似图像[1-10] .jpg的图案 但我想要的是像上面这样获取gallley但也喜欢domain.com/gallery/ 我有什么机会让这个工作。
希望有人可以给我打电话。
$parts = preg_split("/\[\d+-\d+\]/", $url, -1, PREG_SPLIT_DELIM_CAPTURE);
preg_match_all("/\[\d+-\d+\]/", $url, $matches, PREG_PATTERN_ORDER);
$parts_number = count($parts);
$matches_number = count($matches[0]);
// JYM
if ($parts_number==1) {
$image_alt_url=$url;
$url = str_replace("[", '', $url);
$url = str_replace("]", '', $url);
$alto = str_replace("/", '_', $image_alt_url);
$alto = str_replace("www", '', $alto);
$alto = str_replace("http", '', $alto);
$alto = str_replace("https", '', $alto);
$alto = str_replace("jpg", '', $alto);
$alto = str_replace("com", '', $alto);
$alto = str_replace("net", '', $alto);
$alto = str_replace("info", '', $alto);
$alto = str_replace(".com.np", '', $alto);
$alto = str_replace("org", '', $alto);
$alto = str_replace(".", '', $alto);
$alto = str_replace(":_", '', $alto);
$alto = str_replace("-", '_', $alto);
$alto = preg_replace("/[^a-z-_]/",'',$alto);
$alto = str_replace("__", '_', $alto);
$alto = str_replace("___", '_', $alto);
$alto = str_replace("_", '-', $alto);
$alto=substr($alto, 1, -1);
$ary_header = get_headers($url, 1);
$filesize = $ary_header['Content-Length'];
答案 0 :(得分:0)
由于您的问题没有提供任何样本输入,也没有预期的结果,我不得不做出几个假设:
$url="https://www.example.com/gallery/image3.jpg, example.com/gallery/image9.jpg, http://example.com/gallery/image14.JPG";
if(!preg_match_all("/([^, ]*\/)([^,]*?(\d+).jpg)/i",$url,$matches,PREG_SET_ORDER)){
echo "No Matches Found";
}
foreach($matches as $match){
list($fullstring,$path,$filename,$id)=$match;
echo "<div>fullstring=$fullstring</div>";
echo "<div>path=$path</div>";
echo "<div>filename=$filename</div>";
echo "<div>id=$id</div><br>";
// ...now do any necessary substring processing.
}
输出:
fullstring=https://www.example.com/gallery/image3.jpg
path=https://www.example.com/gallery/
filename=image3.jpg
id=3
fullstring=example.com/gallery/image9.jpg
path=example.com/gallery/
filename=image9.jpg
id=9
fullstring=http://example.com/gallery/image14.JPG
path=http://example.com/gallery/
filename=image14.JPG
id=14
通过隔离您希望保留的字符串部分,您可以减少str_replace()
/ preg_replace
工作量。