1 截取文章里的链接 $pattern = '~[a-z]+://\S+~'; preg_match_all($pattern, $link, $out) if (empty($out[0])
$pattern = '~[a-z]+://\S+~'; preg_match_all($pattern, $link, $out) if (empty($out[0])) exit('请输入带有链接的文本'); $link = $out[0][0];
composer require guzzlehttp/guzzle
$headers = [ 'cookie' => '', 'user-agent' => 'Mozilla/5.0 (windows NT 10.0; Win64; x64) AppleWEBKit/537.36 (Khtml, like Gecko) Chrome/86.0.4240.198 Safari/537.36', ]; $client = new Client(); $response = $client->get($link,['headers' => $headers]); $data = $response->getBody()->getContents();
curl 方式
$cookie = ""; $request_link='';//请求链接 $post_data = '';//请求数据 $referer='';//刷新链接 $agent='';//代理 $header=[];//头部信息 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$request_link); curl_setopt($ch,CURLOPT_HTTPHEADER,$header); curl_setopt($ch, CURLOPT_COOKIE, $cookie); curl_setopt($ch, CURLOPT_REFERER,$referer); curl_setopt($ch,CURLOPT_USERAGENT,$agent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_ENcoding, 'gzip,deflate'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); $output = curl_exec($ch); curl_close($ch); return $output;
gethostbyname($host)
$chars = [ 1 => '0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 2 => '123456789', 3 => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|', 4 => 'abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ]; $str = ''; for ($i = 0; $i < $length; $i++) { $str .= $chars[$type][mt_rand(0, strlen($chars[$type]) - 1)]; } return $str;
$y = date('y'); $m=date('m'); $d=date('d'); $h=date('h'); $i=date('i'); $s=date('s'); $date=ceil($y+$m+$d).ceil($h+$i+$s); $digits = intval($digits); if ($digits < 14) return '随机单号大于14字符'; $digits = $digits - strlen($date) - strlen($prefix); if ($digits < 0) return '随机单号生成失败'; $rand = ''; $num = floor($digits / 10); for ($i = 0; $i < $num; $i++) { $rand .= str_pad(mt_rand(1, (int)9999999999), 10, '0', STR_PAD_LEFT); } if ($digits % 10 != 0) { $rand .= str_pad(mt_rand(1, (int)substr(9999999999, 0, $digits - ($num * 10))), $digits - ($num * 10), '0', STR_PAD_LEFT); } $order_number = $prefix . $date . $rand; return $order_number;
$string = ' ' . $string; $n = strpos($string, $start); if ($n == 0) return ''; $n += strlen($start); $len = is_null($end)?strlen($string)-$n:strpos($string, $end, $n) - $n; return substr($string, $n, $len);
来源地址:https://blog.csdn.net/weixin_39687736/article/details/131693838
--结束END--
本文标题: PHP截取两个字符中间内容,php获取文章链接,php的curl模拟请求,php的随机字符,php的获取IP,php的生成随机单号
本文链接: https://lsjlt.com/news/388810.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0