Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.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向数据库发送字符串_Php - Fatal编程技术网

使用php向数据库发送字符串

使用php向数据库发送字符串,php,Php,我这里有一个问题,我知道我想做什么,但无法绕开编码,我已经用我的PHP代码打开了一个文本文档,现在我想跳过文档的前59行,然后在跳过这59行之后将每个句子的前4行发送到我已经创建的数据库。我已经写下了打开文档并跳过前59行的代码,现在我需要做的就是将每行的前4个字符串发送到数据库。这是我的密码 $url = 'C:\portsdocx.txt'; //my text document $file = file_get_contents($url) //opens up my document

我这里有一个问题,我知道我想做什么,但无法绕开编码,我已经用我的PHP代码打开了一个文本文档,现在我想跳过文档的前59行,然后在跳过这59行之后将每个句子的前4行发送到我已经创建的数据库。我已经写下了打开文档并跳过前59行的代码,现在我需要做的就是将每行的前4个字符串发送到数据库。这是我的密码

$url = 'C:\portsdocx.txt'; //my text document

$file = file_get_contents($url) //opens up my document
or die("Could Not Open The TEXT File<hr /> " . mysql_error());
$file = implode("\n", array_slice(explode("\n", $file), 59));// skips the first 59 lines
提前感谢。

是的,请使用explode:

$line = explode(' ', $data, 4);
mysql_query("INSERT into registry
    ('ServiceName','PortNumber','TransportProtocol','Description')
    VALUES('".$line['0']."','".$line['1']."','".$line['2']."','".$line['3']."')");

问题是什么?我不太明白。
$line = explode(' ', $data, 4);
mysql_query("INSERT into registry
    ('ServiceName','PortNumber','TransportProtocol','Description')
    VALUES('".$line['0']."','".$line['1']."','".$line['2']."','".$line['3']."')");