我正在寻找vb.net相当于这个功能:我没有PHP的经验但遇到这个代码显然从谷歌图片给你一个随机的图像网址
function GetRandomImageURL($topic='', $min=0, $max=100)
{
// get random image from Google
if ($topic=='') $topic='image';
$ofs=mt_rand($min, $max);
$geturl='http://www.google.ca/images?q=' . $topic . '&start=' . $ofs . '&gbv=1';
$data=file_get_contents($geturl);
$f1='<div id="center_col">';
$f2='<a href="/imgres?imgurl=';
$f3='&imgrefurl=';
$pos1=strpos($data, $f1)+strlen($f1);
if ($pos1==FALSE) return FALSE;
$pos2=strpos($data, $f2, $pos1)+strlen($f2);
if ($pos2==FALSE) return FALSE;
$pos3=strpos($data, $f3, $pos2);
if ($pos3==FALSE) return FALSE;
return substr($data, $pos2, $pos3-$pos2);
}
答案 0 :(得分:1)
它主要是字符串操作,构建图像URL。它在此行
上的索引0
和100
之间选择一个伪随机图像
$ofs=mt_rand($min, $max);
使用.Net
中的Random
类可以实现同样的目的
Dim rnd As New Random()
Dim ofs As Int = rnd.Next(min, max)
我将字符串操作留给OP,但使用StringBuilder
类或者String.Format
类可能更好。
值得考虑的是0
到100
界限是否过于强烈。