How can i parse this result

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manjava
    New Member
    • Sep 2009
    • 132

    How can i parse this result

    I have this result i want to parse and get Lfam for example in following my result :

    Code:
    object(stdClass)[159]
    > >       public 'PapFamType' => 
    > >         array (size=28)
    > >           0 => 
    > >             object(stdClass)[164]
    > >               public 'Owner' => string '' (length=0)
    > >               public 'Fam' => string 'CMM' (length=3)
    > >               public 'Lfam' => string 'Couché moderne mat' (length=19)
    >               public 'Ctype' => string 'CM5' (length=3)
    >               public 'Ltype' => string 'Chromomat' (length=9)
    >               public 'Ccoul' => string 'BC' (length=2)
    >               public 'Lcoul' => string 'BLANC' (length=5)
    >               public 'Gramm' => string '400' (length=3)
    >               public 'PoidsM' => string '0' (length=1)
    >              
    >           1 => 
    >             object(stdClass)[165]
    >               public 'Owner' => string '' (length=0)
    >               public 'Fam' => string 'CMM' (length=3)
    >               public 'Lfam' => string 'Couché Moderne Mat' (length=19)
    >               public 'Ctype' => string 'CM5' (length=3)
    >               public 'Ltype' => string 'Chromomat' (length=9)
    >               public 'Ccoul' => string 'IV' (length=2)
    >               public 'Lcoul' => string 'IVOIRE NATUREL' (length=14)
    >               public 'Gramm' => string '250' (length=3)
    >               public 'PoidsM' => string '0' (length=1)
    How I can parse this result ?

    I searched, but I didn't found out how I could do it.

    Thanks
  • computerfox
    Contributor
    • Mar 2010
    • 276

    #2
    I would use regex and build a function that looks up the key. So something like this:

    Code:
    <?php
     $data="lookup.txt";
     $data=file_get_contents($data);
     $key="Lfam";
     function lookup($key,$data){
      $reg="/(^".$key.")*".$key."(.)*/";
      print $reg."\n";
      preg_match_all($reg,$data,$results);
      print "Results: ".(count($results[0]))."\n";
      for($i=0;$i<count($results[0]);$i++){
       print $results[0][$i];
       print "\n";
      }
     }
     lookup($key,$data);
    ?>

    How's that?

    Comment

    • manjava
      New Member
      • Sep 2009
      • 132

      #3
      how can i put the result in table to get each one

      Comment

      • computerfox
        Contributor
        • Mar 2010
        • 276

        #4
        Pull the result of the regex? And each value of the regex result?
        You would then use explode($result ,"=>") to get the columns.

        Comment

        • manjava
          New Member
          • Sep 2009
          • 132

          #5
          so i do that:
          Code:
          foreach($quote_infos->Components->Component as $component_index=>$component) {
          		$quote_desc .= ($component_index+1).') '.$component->Title."\n";
          		$quote_desc .= 'Format : '."\t".$component->FmtStd->Width.' x '.$component->FmtStd->Height.' cm'."\n";
          		$quote_desc .= 'Contenu : '."\t".$component->NbSections.' x '.$quote_infos->Quantity.' ex.'."\n";
          		if(isset($component->Paper->Family)) {
          			if(isset($component->Paper->Type) && isset($component->Paper->Color)) {
          				$paper_types = getPaperTypes($component->Paper->Family);
          				$quote_desc .= 'Papier : '."\t".$paper_families[$component->Paper->Family].' - '.$paper_types[$component->Paper->Type].' - '.$component->Paper->Color.' - '.$component->Paper->Weight.' g/m2'."\n";
          			}
          		}
          	}
          i need this $quote_desc contains three lines and i need each line stocked in varaible how can i do that in table

          Thanks in advance

          Comment

          • computerfox
            Contributor
            • Mar 2010
            • 276

            #6
            This looks like you're building the string instead of "parsing" it.
            What is it exactly that you're trying to do and what is the full code you have so far?

            Comment

            • manjava
              New Member
              • Sep 2009
              • 132

              #7
              i need how can i din table contains this result $quote_desc and get each index conatins the line of information

              Comment

              • computerfox
                Contributor
                • Mar 2010
                • 276

                #8
                Based on the information that you're giving me, here's SOMETHING what it should look like.
                I have a file named lookup.txt (you can name it whatever you want) and I'm pulling this in to a variable called data. The following code assumes that you have a file with the contents and you have a key with the paper name.
                Code:
                <?php
                 $data="lookup.txt";
                 $data=file_get_contents($data);
                 $key="Lfam";
                 $reg="/(^".$key.")*".$key."(.)*/";
                 preg_match_all($reg,$data,$results);
                 print "Results: ".(count($results[0]))."\n";
                 print "<table id='plain-table'>";
                 print "<tr>";
                 print "<th>Paper Name</th>";
                 print "<th>Paper Type</th>";
                 print "<th>Paper Length</th>";
                 print "<tr>";
                 for($i=0;$i<count($results[0]);$i++){
                  $row=$results[0][$i];
                  $cols=explode("=>",$row);
                  $name=str_replace("public '","",$cols[0]);
                  $name=str_replace("'","",$name);
                  $cols2=explode("' (length=",$cols[1]);
                  $type=str_replace("string '","",$cols2[0]);
                  $length=str_replace(")","",$cols2[1]);
                  print "<tr>";
                  print "<td>".$name."</td>";
                  print "<td>".$type."</td>";
                  print "<td>".$length."</td>";
                  print "</tr>";
                 }
                ?>


                PS: By the sound of it, I assume you have a print shop? If so, you can take a look at this database-driven system I built a while back:

                Comment

                Working...