dongyang1518 2013-03-26 17:49
浏览 7

通过拆分php [duplicate]从字符串创建表

This question already has an answer here:

I have an string in php like this pid1+2+price1+20+qty1+2+pid2+3+price2+20+qty2+1+ which is an outcome processing of some function. now I need to create table which should display the above result as

      pid price qty
       2    20   2
       3    40   1

note: the result should be displayed as a string thanks

the function which i used to create the string is

$a=var_export($_REQUEST);
$b ='';
foreach($_REQUEST as $key=>$value)
{
    $b.=$key."+".$value."+";
}
</div>
  • 写回答

1条回答 默认 最新

  • dpsfay2510 2013-03-26 18:05
    关注
    $array = array();
    foreach ($_REQUEST as $key => $value) {
      preg_match('/^([a-z]+)(\d+)$/', $key, $match);
      $array[$match[2]][$match[$1] = $value;
    }
    echo "<table><tr><th>pid</th><th>price</th><th>qty</th></tr>";
    foreach ($array as $row) {
      echo "<tr><td>$row[pid]</td><td>$row[price]</td><td>$row[qty]</td></tr>";
    }
    echo "</table>";
    
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改