php 读取TXT文本生成 想要的数据格式
来源:互联网 发布:精易论坛淘宝采集 编辑:程序博客网 时间:2024/05/22 21:21
控制器
public function index() { $_rows = M('tb')->where(['areaType' => 2])->select(); foreach ($_rows as $k => $v) { echo "pro_array[" . $v['areaCode'] . "]" . "=" . '"' . $v['areaName'] . '";'; echo '<br>'; echo "city_array[" . $v['areaCode'] . "]" . "=" . "[]"; echo '<br>'; echo "city_array[" . $v['areaCode'] . "]" . "[0]" . "=" . '"' . "请选择" . '";'; echo '<br>'; $_rows2 = M('tb')->where(['areaType' => 3, 'areaParentId' => $v['areaCode']])->select(); foreach ($_rows2 as $k2 => $v2) { echo "city_array[" . $v['areaCode'] . "]" . "[" . $v2['areaCode'] . "]" . "=" . '"' . $v2['areaName'] . '";'; echo '<br>'; echo "l_arr[" . $v2['areaCode'] . "]" . "=" . '"' . $v2['areaName'] . '";'; echo '<br>'; echo "qu_arr[" . $v2['areaCode'] . "]" . "=" . "[]" . ";"; echo '<br>'; echo "qu_arr[" . $v2['areaCode'] . "]" . "[0]" . "=" . '"' . "请选择" . '";'; echo '<br>'; $_r = M('tb')->where(['areaType' => 4, 'areaParentId' => $v2['areaCode']])->find(); if ($_r) { $_rows3 = M('tb')->where(['areaType' => 4, 'areaParentId' => $v2['areaCode']])->select(); foreach ($_rows3 as $k3 => $v3) { echo "qu_arr[" . $v2['areaCode'] . "]" . "[" . $v3['areaCode'] . "]" . "=" . '"' . $v3['areaName'] . '";'; echo '<br>'; } } else { $_rows3 = M('tb')->where(['areaType' => 5, 'areaParentId' => $v2['areaCode']])->select(); foreach ($_rows3 as $k3 => $v3) { echo "qu_arr[" . $v2['areaCode'] . "]" . "[" . $v3['areaCode'] . "]" . "=" . '"' . $v3['areaName'] . '";'; echo '<br>'; } } } } }
<?phpheader("Content-type: text/html; charset=gb2312");$handle = @fopen("111.txt", "r");function zhongwen($text){ $aaaa= substr($text,6,100)."<br>"; //获取每一行的第2个参数 //把GB2312编码转化为 UTF-8编码 $str = mb_convert_encoding($aaaa, 'UTF-8', 'GB2312'); //正则匹配 preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $str, $matches); //把匹配到的数组连接为字符串 $str = implode('', $matches[0]); //把UTF-8编码转化为 GB2312编码 $text2 = mb_convert_encoding($str, 'GB2312', 'UTF-8'); return $text2;}if ($handle) { while (!feof($handle)) { $buffer = fgets($handle, 4096); $text =$buffer; //获取一行数据 $aaaa = substr($text,6,1000); //获取每1行的第一个参数 $text1 = substr($text,0,6); //获取每1行的第一个参数 $text2 = zhongwen($text); $par = "/[\x80-\xff]/"; $text3 = preg_replace($par,"",$aaaa)."<br>"; if($text3==1){ echo "pro_array"."[$text1]"."=".$text2.";<br>"; echo "city_array[$text1]=[];"."<br>"; echo "city_array[$text1][0]="."请选择".";<br>"; /* while ($handle) { $buffer = fgets($handle, 4096); $text =$buffer; //获取一行数据 $aaaa = substr($text,6,1000); //获取每1行的第一个参数 $text1 = substr($text,0,6); //获取每1行的第一个参数 $text2 = zhongwen($text); $par = "/[\x80-\xff]/"; $text3 = preg_replace($par,"",$aaaa)."<br>"; //return $c; }*/ } } fclose($handle); // 关闭}function city($city,$handle){ $c = []; if ($handle) { while (!feof($handle)) { $buffer = fgets($handle, 4096); $text =$buffer; //获取一行数据 $aaaa = substr($text,6,1000); //获取每1行的第一个参数 $text1 = substr($text,0,6); //获取每1行的第一个参数 $text2 = zhongwen($text); $par = "/[\x80-\xff]/"; $text3 = preg_replace($par,"",$aaaa)."<br>"; if($text3==$city){ echo "city_array[$city][$text1]=".$text2.";<br>"; } //return $c; } fclose($handle); // 关闭 }}?>
<?
error_reporting(E_ALL ^ E_DEPRECATED);
header("Content-type: text/html; charset=gb2312");
$handle = @fopen("111.txt", "r");
$conn = @ mysql_connect("localhost", "root", "root") or die("数据库链接错误");
mysql_select_db("test", $conn);
mysql_query("set names 'GBK'"); //使用GBK中文编码;
function zhongwen($text){
$aaaa= substr($text,6,100)."<br>"; //获取每一行的第2个参数
//把GB2312编码转化为 UTF-8编码
$str = mb_convert_encoding($aaaa, 'UTF-8', 'GB2312');
//正则匹配
preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $str, $matches);
//把匹配到的数组连接为字符串
$str = implode('', $matches[0]);
//把UTF-8编码转化为 GB2312编码
$text2 = mb_convert_encoding($str, 'GB2312', 'UTF-8');
return $text2;
}
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
$text =$buffer; //获取一行数据
$aaaa = substr($text,6,1000); //获取每1行的第一个参数
$text1 = substr($text,0,6); //获取每1行的第一个参数
$text2 = zhongwen($text);
$par = "/[\x80-\xff]/";
$text3 = preg_replace($par,"",$aaaa);
//城市
if($text3==1){
echo "pro_array"."[$text1]"."=".$text2.";<br>";
echo "city_array[$text1]=[];"."<br>";
echo "city_array[$text1][0]="."xuanze".";<br>";
$_sql = "SELECT * FROM qiuyang WHERE c = '$text1'";
$_result = mysql_query($_sql);
while($_rows = mysql_fetch_array($_result,MYSQL_ASSOC)){
$c = $_rows['c'];
$a = $_rows['a'];
echo "city_array[$c][$a]=".$_rows['b'].";<br>";
//区县
echo "l_arr[$a]=".$_rows['b'].";<br>";
echo "qu_arr[$a]="."[]".";<br>";
echo "qu_arr[$a][0]="."xuanze".";<br>";
$_sql2 = "SELECT * FROM qiuyang WHERE c = '$a'";
$_result2 = mysql_query($_sql2);
while($_rows2 = mysql_fetch_array($_result2,MYSQL_ASSOC)){
$c2 = $_rows2['c'];
$a2 = $_rows2['a'];
echo "qu_arr[$c2][$a2]=".$_rows2['b'].";<br>";
}
}
}
}
fclose($handle); // 关闭
}
?>
插入数据
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?
error_reporting(E_ALL ^ E_DEPRECATED);
header("Content-type: text/html; charset=gb2312");
$handle = @fopen("111.txt", "r");
$conn = @ mysql_connect("localhost", "root", "root") or die("数据库链接错误");
mysql_select_db("test", $conn);
mysql_query("set names 'GBK'"); //使用GBK中文编码;
function zhongwen($text){
$aaaa= substr($text,6,100)."<br>"; //获取每一行的第2个参数
//把GB2312编码转化为 UTF-8编码
$str = mb_convert_encoding($aaaa, 'UTF-8', 'GB2312');
//正则匹配
preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $str, $matches);
//把匹配到的数组连接为字符串
$str = implode('', $matches[0]);
//把UTF-8编码转化为 GB2312编码
$text2 = mb_convert_encoding($str, 'GB2312', 'UTF-8');
return $text2;
}
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
$text =$buffer; //获取一行数据
$aaaa = substr($text,6,1000); //获取每1行的第一个参数
$text1 = substr($text,0,6); //获取每1行的第一个参数
$text2 = zhongwen($text);
$par = "/[\x80-\xff]/";
$text3 = preg_replace($par,"",$aaaa);
//$_sql = "INSERT INTO qiuyang ( a,b,c) VALUES ('$text1','$text2', '$text3' )";
// $_result = mysql_query($_sql);
//echo $text1;
//echo $text2;
//echo $text3;
}
fclose($handle); // 关闭
}
?>
- php 读取TXT文本生成 想要的数据格式
- php 快速读取txt或文本
- 读取文本字符串,并生成以字符串命名的txt文件
- 使用Python将TXT文本内容读取后生成指定XML格式的文件
- vb 读取txt文本的行数
- java读取txt文本的内容
- matlab 读取含有文本的txt
- txt文本文档的创建和读取
- java读取txt文本
- 读取txt文本
- txt文本读取删除
- C++ 读取txt文本
- 使用 PHP 读取文本(TXT)文件 并分页显示
- PHP 生成接口数据格式
- 处理生成VOC的数据格式的test.txt train.txt trainval.txt val.txt 和SSD的imdb数据格式以及ssd的训练
- 读取TXT文件,和生成TXT文件的方法
- 读取TXT文件,和生成TXT文件的方法
- PHP读取TXT中文乱码的解决方法
- 2016 年度消费信贷建模小结
- 例题7-5 UVA 129 Krypton Factor (困难的串,搜索)
- Echarts 经验
- 如何修改Android APP的图标和名字
- Sqoop2-2:There are issues with entered data, please revise your input:
- php 读取TXT文本生成 想要的数据格式
- 【VS开发】【miscellaneous】 Windows下配置Git
- HandlerThread深入理解
- Android Studio设置注释模板
- xml可以分页案例
- [C/C++11]_[初级]_[std::bind介绍和使用]
- centos命令
- Linux下察看swap分区大小及增加分区大小
- win7下的Django学习