doucheng2053 2013-07-17 15:06
浏览 91
已采纳

将数组转换为单个变量

I am using simplehtmldom to parse a webpage and extract a data and then put it in a mysql database. I successfully extracted the data and put it in array but now the problem i am facing is how to convert this array to variable so that I may use it in my database query to insert the record in the specific fields. I want to convert array to individual variables

here is the code

<?php
     include("simple_html_dom.php");

     $html = file_get_html('abc.html'); 

     $sched = array();
     foreach ( $html->find('tr[class=highlight-darkgrey]') as $event ) {
         $item['title'] = trim($event->find('td', 1)->plaintext);

         $sched[] = $item;
    }

    var_dump($sched);
?>

and the output is

array (size=6)
 0 => 
 array (size=1)
  'title' => string 'Network admin, field engineer, engineering analyst, sales  executive, PA to HR director Required by Telecommunication Company' (length=124)
 1 => 
 array (size=1)
  'title' => string 'Karachi, Hydrabad, Lahore, Rawalpindi, Peshawar, Multan, Faisalabad' (length=67)
 2 => 
 array (size=1)
  'title' => string '5 - 6 Years' (length=11)
 3 => 
 array (size=1)
  'title' => string 'Knowledge of Field' (length=18)
 4 => 
 array (size=1)
  'title' => string '' (length=0)
 5 => 
 array (size=1)
  'title' => string '- Salary and incentives are not full and final. Can be discussed on final interview.

Can please somebody help me in achieving it. Thanks in advance

  • 写回答

5条回答 默认 最新

  • drblhw5731 2013-07-17 15:15
    关注

    Well, if this needs to go in specific fields then you can do something like this:

    INSERT INTO table_name (column1, column2, column3,...)
    VALUES ($sched[0]['title'], $sched[1]['title'], $sched[2]['title'],...);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?