引言
PHP图片识别
1. PHP与图片识别
2. PHP图片识别接口
<?php
class Sample
{
public function run()
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://netocr.com/api/recoglenliu.do",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPVERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array(
'img' => '/9j',
'key' => 'Mg',
'secret' => '36',
'typeId' => '2008',
'outvalue' => ''
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
}
PHP正则提取
1. PHP正则表达式
PHP内置了正则表达式支持,可以用于字符串匹配、替换、分割等操作。以下是一些常用的PHP正则表达式:
'/\d/':匹配数字'/\w/':匹配字母、数字和下划线'/\s/':匹配空白字符
2. PHP正则提取图片src
<?php
header("Content-type:text/html;charset=utf-8");
$str = '<li><a href"https://www.mzitu.com/169017" target"blank"><img src"https://i.meizitu.net/thumbs/2019/02/16901710d01236.jpg" alt"肉感美女刘钰儿性感图片,丰满成熟女人味十足" width"236" height"354" /></a><span><a href"https://www.mzitu.com/169017" target"blank">肉感美女刘钰儿性感图片,丰满成熟女人味十足</a></span><span class"time">2019-02-14</span></li>';
preg_match_all('/<img\s+src="([^"]+)"\s*/', $str, $matches);
foreach ($matches[1] as $match) {
echo $match . "<br>";
}
?>