问题描述:


对应HTML代码如下:

<table style="table-layout:fixed; width:100%; border-collapse:collapse; border-spacing:0;"><colgroup><col width="16%"><col width="14%"><col width="14%"><col width="14%"><col width="14%"><col width="14%"><col width="14%"></colgroup><thead><tr><th style="margin:0; padding:0; height:45px; font-weight:bold; font-size:12px; text-align:center; border-bottom:1px solid #ddd;" colspan="7">详细尺码信息</th></tr></thead><tbody><tr><td style="margin:0; padding:10px 0; height:30px; text-align:left; font-size:13px;">面料</td><td style="margin:0; padding:10px 0; height:30px; text-align:left; font-size:13px;" colspan="6">上衣-棉85/人造丝10/弹力5&nbsp; 裙-棉95/弹力5</td></tr><tr><td style="margin:0; padding:10px 0; height:30px; text-align:left; font-size:13px;">尺码</td><td style="margin:0; padding:10px 0; height:30px; text-align:left; font-size:13px;" colspan="6">s,m</td></tr><tr><td style="margin:0; padding:10px 0; height:30px; text-align:left; font-size:13px;">颜色</td><td style="margin:0; padding:10px 0; height:30px; text-align:left; font-size:13px;" colspan="6">白色</td></tr><tr><td style="margin:0; padding:10px 0; height:30px; text-align:left; font-size:13px;">洗涤方式</td><td style="margin:0; padding:10px 0; height:30px; text-align:left; font-size:13px;" colspan="6">干洗/手洗</td></tr><tr><td style="margin:0; padding:10px 0; height:30px; text-align:left; font-size:13px;">备注</td><td style="margin:0; padding:10px 0; height:30px; text-align:left; font-size:13px;" colspan="6"><p style="margin:0; padding:0; line-height:28px; font-size:13px;">*由于测量方法不同,尺寸数据可能存在误差</p><p style="margin:0; padding:0; line-height:28px; font-size:13px;">*由于电脑显示器的分辨率不同,颜色可能出现一些不同的现象</p><p>&nbsp;</p></td></tr></tbody><tfoot><tr><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd; font-weight:bold; border-color:#333;">尺码(cm)</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd; font-weight:bold; border-color:#333;">肩宽</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd; font-weight:bold; border-color:#333;">袖长</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd; font-weight:bold; border-color:#333;">胸宽</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd; font-weight:bold; border-color:#333;">腰宽</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd; font-weight:bold; border-color:#333;">全长</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd; font-weight:bold; border-color:#333;">-</td></tr><tr><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">上衣</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">41</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">20</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">47</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">-</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">62</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">-</td></tr><tr><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd; font-weight:bold; border-color:#333;">下衣尺码(cm)</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd; font-weight:bold; border-color:#333;">腰宽</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd; font-weight:bold; border-color:#333;">臀宽</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd; font-weight:bold; border-color:#333;">底宽</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd; font-weight:bold; border-color:#333;">内长度</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd; font-weight:bold; border-color:#333;">全长</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd; font-weight:bold; border-color:#333;">全长</td></tr><tr><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">M</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">34</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">38</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">-</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">-</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">41-51</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">-</td></tr><tr><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">L</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">36</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">40</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">-</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">-</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">42-52</td><td style="margin:0; padding:10px 0; height:30px; font-size:12px; font-weight:400; text-align:left; border-top:1px solid #ddd;">-</td></tr></tfoot></table>

现需将该尺码表整理成类似如下数据格式:

Material:Cotton
Size:上衣/M/L
上衣:waist:32 hip:42 length:42.5
M:waist:34 hip:44 length:43
L:waist:34 hip:44 length:43

解决方案:

<?php
private function getPrdDtiSize($prd_dti)
{/*****************************************************************************************************************************$tfoot_header_line                 = array();$table_size_list                   = array();$dti_size                          = array();$tmp_str                           = '';$prdDtiLngMNG                      = Cl::get('PrdDtiLngManager');/****************************************************************************************************************************/preg_match_all("@<tbody[^>]*?>[\s\S]*?<\/tbody>@i",$prd_dti['prd_dti_bdy_htm'], $size_tbody);//面料 preg_match_all("@<tfoot[^>]*?>[\s\S]*?<\/tfoot>@i",$prd_dti['prd_dti_bdy_htm'], $size_tfoot);//详细尺码preg_match_all("@<td[^>]*?>[\s\S]*?<\/td>@i",$size_tbody[0][0], $tmp_tbody_datas);preg_match_all("@<td[^>]*?>[\s\S]*?<\/td>@i",$size_tfoot[0][0], $tmp_tfoot_datas);//每个单元格preg_match_all("@<tr[^>]*?>[\s\S]*?<\/tr>@i",$size_tfoot[0][0], $tmp_tfoot_lines);//每一行//面料获取&面料翻译foreach ($tmp_tbody_datas[0] AS $key => $tmp_tbody_data){//去掉字符串中的HTML标签及&nbsp;特殊空格$tmp_tbody_datas[0][$key]=str_replace('&nbsp;','',trim((string)strip_tags($tmp_tbody_data)));}$material_key = array_search('面料',$tmp_tbody_datas[0]);$tmp_material_str = $tmp_tbody_datas[0][$material_key+1];//面料 &nbsp;preg_match_all("/[\x{4e00}-\x{9fa5}]+/u", $tmp_material_str, $tmp_material_cns);$material = $tmp_material_str;if(!empty($tmp_material_cns[0])){//数据库中查找对应的英文翻译$tmp_material_ens = $prdDtiLngMNG->loadKeyByPrdDtiLngNmCns( $tmp_material_cns[0], 'prd_dti_lng_nm_cn');if(!empty($tmp_material_ens)){//可用array_column函数处理,但未成功foreach ($tmp_material_ens AS $key => $tmp_material_en){$material_ens[] = $tmp_material_en['prd_dti_lng_nm_en'];}$material = str_replace(array_keys($tmp_material_ens), $material_ens, $tmp_material_str);}}//获取详细尺码表中所有表头出现的所在行数foreach ($tmp_tfoot_lines[0] AS $key => $tmp_tfoot_line){if(stripos($tmp_tfoot_line,'font-weight:bold;') !== false){$tfoot_header_line[] = $key;}}//每个单元格数据按行分组&尺码翻译foreach ($tmp_tfoot_datas[0] AS $key => $tmp_tfoot_data){$tmp_tfoot_datas[0][$key]  = str_replace('&nbsp;',' ',trim((string)strip_tags($tmp_tfoot_data)));}$prd_dti_lngs = $prdDtiLngMNG->loadKeyByPrdDtiLngNmCns( $tmp_tfoot_datas[0], 'prd_dti_lng_nm_cn');foreach ($tmp_tfoot_datas[0] AS $key => $tmp_tfoot_data){$tmp_tfoot_datas[0][$key]  = isset($prd_dti_lngs[$tmp_tfoot_data]) ? $prd_dti_lngs[$tmp_tfoot_data]['prd_dti_lng_nm_en'] : $tmp_tfoot_data;}$tmp_tfoot_line = array_chunk($tmp_tfoot_datas[0],(int)count($tmp_tfoot_datas[0])/count($tmp_tfoot_lines[0]));//每个表头与尺码数据对应,如尺码=>S,腰围=>64foreach ($tfoot_header_line AS $key => $val){if($val != end($tfoot_header_line) ){for($i = $val; $i < $tfoot_header_line[$key+1]-1; $i++){$table_size_list['dti_size'][] = array_combine($tmp_tfoot_line[$val],$tmp_tfoot_line[$i+1]);}}else{for($i = $val; $i < count($tmp_tfoot_lines[0])-1; $i++){$table_size_list['dti_size'][] = array_combine($tmp_tfoot_line[$val],$tmp_tfoot_line[$i+1]);}}}//数据整理成类似如下格式S:waist:32  hip:42  length:42.5foreach ($table_size_list['dti_size'] AS $k => $table_size){$tmp_str = reset($table_size).':';array_shift($table_size);foreach ($table_size AS $key=>$val){$tmp_str .= "$key:$val ";}$dti_size[].=$tmp_str;}$table_size_list['material']   = $material;$size              =array_map('reset',$table_size_list['dti_size']);$table_size_list['simp_size']   = implode('/',$size);//如S/M$table_size_list['dti_size']    = $dti_size;return $table_size_list;
}
?>

Array
(
[dti_size] => Array
(
[0] => jupe:shoulder :41 sleeve:20 chest:47 腰宽:- 全长:62 -:-
[1] => M:腰宽:34 臀宽:38 底宽:- 内长度:- 全长:-
[2] => L:腰宽:36 臀宽:40 底宽:- 内长度:- 全长:-
)
[material] => jupe-棉85/人造丝10/弹力5 裙-棉95/弹力5
[simp_size] => jupe/M/L
)

PHP将商品详情中的尺码表重新进行数据整合并翻译相关推荐

  1. Hibernate 学习心得1: 多对多关系中,中间表无法插入数据。

    Hibernate 学习心得之一 多对多关系中,中间表无法插入数据. 最近学习 spring4+hibernate4,学习中遇到了很多坑. 在这里我来说说我遇到的坑,这里就不介绍如何spring如何集 ...

  2. 查询库中所有的表名及数据量

    sql代码直接执行即可 sqlserver查询库中所有的表名及数据量 SELECTa.name,b.rows FROMsysobjects AS aINNER JOIN sysindexes AS b ...

  3. 不动产测绘数据入库_不动产登记中的房产与地籍测绘数据整合

    不动产登记中的房产与地籍测绘数据整合 摘要:随着房地产领域的快速发展,各级对不动产登记制度越来越重视.不动 产权籍调查是不动产登记的一项基础性工作,建立不动产登记信息数据库离不开 地基测绘和调查.为快 ...

  4. discuz中写一个表单,数据存入到数据库中,再从数据库读出来显示在列表中

    2019独角兽企业重金招聘Python工程师标准>>> 要做到如下的一个效果: 创建的文件有: ./funds.php ./template/PHPChina/funds/funds ...

  5. 从MySQL中导出表中数据_用命令从mysql中导出/导入表结构及数据

    在命令行下mysql的数据导出有个很好用命令mysqldump,它的参数有一大把,可以这样查看: mysqldump 最常用的: mysqldump -uroot -pmysql databasefo ...

  6. 关联数据库中多张表_关联数据

    关联数据库中多张表 在本系列的前两篇文章(" 使用RDF创建数据网 "和" 使用SPARQL查询RDF数据 ")中,您了解了资源描述框架(RDF)以及SPARQ ...

  7. Android 商品详情中规格的联动选择实现

    一 啥也不说了,先看效果吧. 二  这种方式和天猫淘宝的效果区别并不大.但是实现思路应该区别蛮大,毕竟我自己实现的时候很麻烦.具体还是要看 数据是怎么样的 .依靠数据去梳理逻辑. 1  表结构.Jso ...

  8. 使用mybatis操作MySQL中的数据库表1---读取数据

    1)MySQL中创建表 create table student ( id int(11) not null, name varchar(255) default null, email varcha ...

  9. 高并发处理之商品详情页

    首页 博客 专栏·视频 下载 论坛 问答 代码 直播 能力认证 高校 会员中心 收藏 动态 消息 创作中心 高并发处理之商品详情页 卜大伟 2019-01-18 11:13:47  2488  收藏  ...

  10. 商品详情页动态渲染系统:大型网站的多机房4级缓存架构设计

    124_大型电商网站的商品详情页的深入分析 之前,咱们也是说在讲解这个商品详情页系统的架构 缓存架构,高可用服务 商品详情页系统,我们只是抽取了其中一部分来讲解,而且还做了很大程度的简化 主要是为了用 ...

最新文章

  1. Silverlight 2 Customized Control 开发
  2. [知识图谱实战篇] 五.HTML+D3添加鼠标响应事件显示相关节点及边
  3. AC自动机解决字符集很大的情况(可持久化数组优化getfail的过程)
  4. [leetcode] 704.二分查找
  5. 我是服务的执政官-服务发现和注册工具consul简介
  6. pandas Dataframe读取数据表是自定义列名
  7. browser.html – HTML 实现 Firefox UI
  8. 毕啸南专栏 | 对话李开复:AI科学家的转型之路
  9. 《剑指offer》面试题——把数组排成最小的数
  10. 381.O(1)时间插入、删除和获取随机元素-允许重复
  11. Hamcrest 测试匹配框架
  12. 优化设计——多目标函数优化(降维/主目标法、线性加权法、理想点法)——MATLAB编程
  13. react-ative安装expo-linking后运行报错
  14. 原创 | 一文读懂机器学习中的shapley值方法
  15. insmod 加载模块的过程
  16. 新浪微博开发(五)AppList界面
  17. Luminati怎么玩,为用户解决什么问题?
  18. linux卸载mate,【重大更新】最完美的ADB一键卸载工具,新增卸载后悔重装功能,小白福利哈!基于160...
  19. unity快速进入Project窗口文件夹
  20. 社区版pyCharm创建Django项目

热门文章

  1. 北京清大美博节能技术研究院励志人生格言
  2. C语言交换a,b值的几种写法
  3. ArcGIS 线简化算法的使用及两种方法的比较
  4. 1008day1作业:字符串(方法、格式化、strip左右字符)、列表(方法、max、min、去重、统计个数、两列表比较取出大值zip合成新列表)、斐波那契、水仙花数、冒泡排序列表、计算器、九九乘法
  5. Rhino学习教程——1.4
  6. win10系统安装和优化
  7. 微信小程序商城项目实战(第四篇:商品详情页)
  8. ajax返回map的值,同时在sucess返回时的显示
  9. 使用yaf+yar实现基于http的rpc服务
  10. java 变量 英文_java 变量(翻译自Java Tutorials)