Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP&;MYSQL插入到带有文本区域的数据库中(新行和新行插入数据库)?_Php_Mysql - Fatal编程技术网

PHP&;MYSQL插入到带有文本区域的数据库中(新行和新行插入数据库)?

PHP&;MYSQL插入到带有文本区域的数据库中(新行和新行插入数据库)?,php,mysql,Php,Mysql,它将添加所有这4张唱片,干杯 使用以下代码: test:80:test:test:test test:80:test:test:test test:80:test:test:test test:80:test:test:test 更多解释请参见此 请尝试以下代码: $text = trim($_POST['textareaname']); $textAr = explode("\n", $text); // remove the last \n or whitespace cha

它将添加所有这4张唱片,干杯

使用以下代码:

test:80:test:test:test
test:80:test:test:test
test:80:test:test:test
test:80:test:test:test

更多解释请参见此

请尝试以下代码:

 $text = trim($_POST['textareaname']); 
    $textAr = explode("\n", $text);  // remove the last \n or whitespace character
    $textAr = array_filter($textAr, 'trim'); // remove any extra \r characters left behind

    foreach ($textAr as $line) {
        // processing here. 
    } 

我建议你附加

$string = trim($_POST['proxies']);
$stringArray = explode("\n" , $string);
$stringArray = array_filter($stringArray,'trim');

foreach($stringArray as $ $string){
$arrray = explode(':',$string);
$proxy = $arrray[0] . ':' . $arrray[1];
$country = $arrray[2];
$state = $arrray[3];
$city = $arrray[4];
$query = mysqli_query($link,"INSERT INTO `proxies`(`proxy`,`country`, `state`, `city`) VALUES ('{$proxy}', '{$country}', '{$state}', '{$city}')");
}
PHP_EOL-是PHP中的一个行尾常量,将其附加在字符串末尾,而不是“\n”


我希望它能解决这个问题,

Hi,在这里使用我的//processing下的脚本实际上不起作用,我很困惑为什么,当我尝试做test:80:test:test:test:test(5行)时,它在SQL中记录为test:80(新行)test(新行)testtesttest所以在我的数据库中,我得到了最后一行下一行的副本(截图):@user3152114您希望表中只有唯一的ip:port值,对吗?
$string = trim($_POST['proxies']);
$stringArray = explode("\n" , $string);
$stringArray = array_filter($stringArray,'trim');

foreach($stringArray as $ $string){
$arrray = explode(':',$string);
$proxy = $arrray[0] . ':' . $arrray[1];
$country = $arrray[2];
$state = $arrray[3];
$city = $arrray[4];
$query = mysqli_query($link,"INSERT INTO `proxies`(`proxy`,`country`, `state`, `city`) VALUES ('{$proxy}', '{$country}', '{$state}', '{$city}')");
}
PHP_EOL