PHP 中的fgets() 函数可以实现
fgets() 函数从文件指针中读取一行.
fgets(file,length)
参数说明
file 必需.规定要读取的文件.
详细说明
若失败,则返回 false.
如果碰到 PHP 在读取文件时不能识别 Macintosh 文件的行结束符,可以激活 auto_detect_line_endings 运行时配置选项.
例如:
test.txt 文本内容如下:
Hello, this is a test file.
There are three lines here.
This is the last line.
php
//读取一行
$file = fopen("test.txt","r");
echo fgets($file);
fclose($file);
输出:
//循环读取每一行
while(! feof($file)) {
echo $str = fgets($file). "br /";
//这里可以逐行的写入数据库中
//mysql_query("insert into table(id,contents) values(NULL,'".$str."')");
}
你要问什么,如果你的后台里边数据是用逗号分割的话,这个样子是将数据用逗号分割后储存在数组ids中.
foreach($data as $key=$value)
{
$str1 = '#1_1';
$tmp = str_replace($str1,'',$value);
$result1[] = $tmp;
print_r($result1);
str_split函数能实现你这样的功能,把字符串按长度分割为数组,例如:
$str?=?"Hello?Friend";
$arr1?=?str_split($str);
print_r($arr1);
代码输出的结果如下:
Array
(
[0]?=?H
[1]?=?e
[10]?=?n
[11]?=?d
)
[0]?=?Hel
[1]?=?lo
程序开始建立两个数据库连接,函数mysql_query()原型:
resource?mysql_query?(?string?$query?[,?resource?$link_identifier?] )
方法1:在mysql_query函数中指定所用连接,即:
以上就是土嘎嘎小编为大家整理的php拆分拼接数据相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!