我是php语言的新手,很高兴得到它。 文本框上的URL并单击按钮,然后使用面向对象的PHP和正则表达式在页面的div中显示该URL中的所有图像。
<?php
if(isset($_POST["btnGo"])){
$url=$_POST["txtUrl"];
$obj=new ImageExtractor();
$obj->extract_image2($url);
}
//class ImageExtractor
class ImageExtractor{
//method 1
function extract_image($url){
$html=file_get_contents($url);
preg_match_all('/<img[^>]+src=([\'"])([^"\']+)\1/i',$html,$matches);
foreach($matches[2] as $image){
echo "<img src='".$image."' width='200' height='100' style='margin:5px;' />";
}
}
//method 2
function extract_image2($url){
$html = file_get_contents($url);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$tags = $doc->getElementsByTagName('img');
foreach ($tags as $tag) {
echo "<img src='".$tag->getAttribute('src')."' width='200' height='100' style='margin:5px;' />";
}
}
}
?>
<form action="#" method="post">
<input type="text" name="txtUrl" value="https://yahoo.com" placeholder="Enter URL" />
<input type="submit" name="btnGo" value="Go"/>
</form>
答案 0 :(得分:-1)
试试这段代码:
library(data.table)#v1.9.6+
setDT(DATA)[, Days:=cumsum(as.numeric(Date-shift(Date, fill=Date[1L]))), Id]
DATA
# Id Date Variable_x Days
# 1: 1 2015-01-01 70 0
# 2: 1 2015-01-10 NA 9
# 3: 1 2015-01-15 55 14
# 4: 1 2015-01-25 30 24
# 5: 2 2013-02-01 70 0
# 6: 2 2013-03-20 60 47
# 7: 2 2013-04-03 NA 61
# 8: 5 2014-05-06 80 0
# 9: 5 2014-06-07 60 32
#10: 5 2014-06-08 70 33
#11: 5 2014-08-09 50 95
#12: 5 2014-10-10 20 157
但是此代码不能在所有网站上运行,您可以将图像渲染到您的空间并显示来自您空间的图像(主机) 问候 Soroush