I use curl to collect the hyperlink of the title of this site into an array, and then I can"t store it in the database. Baidu has done a lot of ways to convert any array into a string. PS: I am a rookie learning
php
$body = get ("https://codeshelper.com/");
// initialization
function get ($url) {
$ch = curl_init ()
/ / set options, including URL
curl_setopt ($ch, CURLOPT_URL, "$url");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt ($ch, CURLOPT_HEADER, 0);
/ execute and get HTML document contents
$output = curl_exec ($ch);
/ release curl handle
curl_close ($ch); < ch > br $br
/ / printed data
preg_match_all ("/ < div class= "mb5 mt5" > < h4 class= "news__item-title mt0" >. ? < / div > < div class= "article-excerpt" >. ? < / div > / ims",$body,$title); * /
$con= mysqli_connect ("localhost","root","root","test"); / / Link
if (! $con) {/ / determine that $con is not equal to return
die("".mysqli_errno());//diemysqli_errno
} else {
echo "";
};
mysqli_set_charset ($con,"utf8");
foreach ($title as $a = > $b) {
$sql= "insert into tex1("username")values(""$b"");"
$result=mysqli_query($con,$sql);
}
if ($result) {
echo "";
} else {
echo"";
}
mysqli_close ($con);
? >
error prompt: Parse error: syntax error, unexpected"$result" (T_VARIABLE) in D:phpStudyWWWindex2.php on line 31
all kinds of errors are reported in foreach anyway. Generally speaking, this function does not exist, or syntax error.
what I want to achieve is that after curl collection, it is stored in the database but stored in [1] of [0] in the array. I belong to learning while taking examples, which has been bothering me for 3 days.