使用php向数据库发送字符串
我这里有一个问题,我知道我想做什么,但无法绕开编码,我已经用我的PHP代码打开了一个文本文档,现在我想跳过文档的前59行,然后在跳过这59行之后将每个句子的前4行发送到我已经创建的数据库。我已经写下了打开文档并跳过前59行的代码,现在我需要做的就是将每行的前4个字符串发送到数据库。这是我的密码使用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
$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']."')");