473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How can i parse this result

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

Expand|Select|Wrap|Line Numbers
  1. object(stdClass)[159]
  2. > >       public 'PapFamType' => 
  3. > >         array (size=28)
  4. > >           0 => 
  5. > >             object(stdClass)[164]
  6. > >               public 'Owner' => string '' (length=0)
  7. > >               public 'Fam' => string 'CMM' (length=3)
  8. > >               public 'Lfam' => string 'Couché moderne mat' (length=19)
  9. >               public 'Ctype' => string 'CM5' (length=3)
  10. >               public 'Ltype' => string 'Chromomat' (length=9)
  11. >               public 'Ccoul' => string 'BC' (length=2)
  12. >               public 'Lcoul' => string 'BLANC' (length=5)
  13. >               public 'Gramm' => string '400' (length=3)
  14. >               public 'PoidsM' => string '0' (length=1)
  15. >              
  16. >           1 => 
  17. >             object(stdClass)[165]
  18. >               public 'Owner' => string '' (length=0)
  19. >               public 'Fam' => string 'CMM' (length=3)
  20. >               public 'Lfam' => string 'Couché Moderne Mat' (length=19)
  21. >               public 'Ctype' => string 'CM5' (length=3)
  22. >               public 'Ltype' => string 'Chromomat' (length=9)
  23. >               public 'Ccoul' => string 'IV' (length=2)
  24. >               public 'Lcoul' => string 'IVOIRE NATUREL' (length=14)
  25. >               public 'Gramm' => string '250' (length=3)
  26. >               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
Jun 7 '15 #1
7 1397
computerfox
276 100+
I would use regex and build a function that looks up the key. So something like this:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  $data="lookup.txt";
  3.  $data=file_get_contents($data);
  4.  $key="Lfam";
  5.  function lookup($key,$data){
  6.   $reg="/(^".$key.")*".$key."(.)*/";
  7.   print $reg."\n";
  8.   preg_match_all($reg,$data,$results);
  9.   print "Results: ".(count($results[0]))."\n";
  10.   for($i=0;$i<count($results[0]);$i++){
  11.    print $results[0][$i];
  12.    print "\n";
  13.   }
  14.  }
  15.  lookup($key,$data);
  16. ?>
  17.  
http://cp.abelgancsos.com/project.php?id=406
How's that?
Jun 7 '15 #2
manjava
132 100+
how can i put the result in table to get each one
Jun 7 '15 #3
computerfox
276 100+
Pull the result of the regex? And each value of the regex result?
You would then use explode($result,"=>") to get the columns.
Jun 7 '15 #4
manjava
132 100+
so i do that:
Expand|Select|Wrap|Line Numbers
  1. foreach($quote_infos->Components->Component as $component_index=>$component) {
  2.         $quote_desc .= ($component_index+1).') '.$component->Title."\n";
  3.         $quote_desc .= 'Format : '."\t".$component->FmtStd->Width.' x '.$component->FmtStd->Height.' cm'."\n";
  4.         $quote_desc .= 'Contenu : '."\t".$component->NbSections.' x '.$quote_infos->Quantity.' ex.'."\n";
  5.         if(isset($component->Paper->Family)) {
  6.             if(isset($component->Paper->Type) && isset($component->Paper->Color)) {
  7.                 $paper_types = getPaperTypes($component->Paper->Family);
  8.                 $quote_desc .= 'Papier : '."\t".$paper_families[$component->Paper->Family].' - '.$paper_types[$component->Paper->Type].' - '.$component->Paper->Color.' - '.$component->Paper->Weight.' g/m2'."\n";
  9.             }
  10.         }
  11.     }
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
Jun 7 '15 #5
computerfox
276 100+
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?
Jun 7 '15 #6
manjava
132 100+
i need how can i din table contains this result $quote_desc and get each index conatins the line of information
Jun 7 '15 #7
computerfox
276 100+
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.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  $data="lookup.txt";
  3.  $data=file_get_contents($data);
  4.  $key="Lfam";
  5.  $reg="/(^".$key.")*".$key."(.)*/";
  6.  preg_match_all($reg,$data,$results);
  7.  print "Results: ".(count($results[0]))."\n";
  8.  print "<table id='plain-table'>";
  9.  print "<tr>";
  10.  print "<th>Paper Name</th>";
  11.  print "<th>Paper Type</th>";
  12.  print "<th>Paper Length</th>";
  13.  print "<tr>";
  14.  for($i=0;$i<count($results[0]);$i++){
  15.   $row=$results[0][$i];
  16.   $cols=explode("=>",$row);
  17.   $name=str_replace("public '","",$cols[0]);
  18.   $name=str_replace("'","",$name);
  19.   $cols2=explode("' (length=",$cols[1]);
  20.   $type=str_replace("string '","",$cols2[0]);
  21.   $length=str_replace(")","",$cols2[1]);
  22.   print "<tr>";
  23.   print "<td>".$name."</td>";
  24.   print "<td>".$type."</td>";
  25.   print "<td>".$length."</td>";
  26.   print "</tr>";
  27.  }
  28. ?>
  29.  
http://cp.abelgancsos.com/project.php?id=407

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:

http://safe.abelgancsos.com/public_p...PaperWorks.zip
Jun 7 '15 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: sky2070 | last post by:
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in c:\inetpub\wwwroot\session.php on line 19 can anyone tell me what is wrong with this code??? <? // Define the Session...
2
by: Salim | last post by:
Hi people, keep getting this errorParse error: parse error, unexpected T_STRING in order_fns.php line 91. the code is below for the file and I've indicated line 91 <?php function...
1
by: chuck amadi | last post by:
By the way list is there a better way than using the readlines() to > > >parse the mail data into a file , because Im using > > >email.message_from_file it returns > > >all the data i.e reads one...
2
by: praba kar | last post by:
Dear all, I want to parse the system functions output but I couldn't do it. Kindly assist me in this task. eg) bytesused = os.system('du -sh /Users/enmail') if I print this bytesused...
22
by: Ram Laxman | last post by:
Hi all, I have a text file which have data in CSV format. "empno","phonenumber","wardnumber" 12345,2234353,1000202 12326,2243653,1000098 Iam a beginner of C/C++ programming. I don't know how to...
1
by: Charlie T | last post by:
hello, I need a little guidance here... I am tring to parse out an XML file, but with some restrictions. here is my XML FILE: ---------XML----------- <XML> <Cam name="01">...
6
by: Ehartwig | last post by:
I recently created a script for user verification, solved my emailing issues, and then re-created the script in order to work well with the new PHP 5 that I installed on my server. After...
3
by: Jon Davis | last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST" The problem: // this fails on PST DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST"); Help? Jon
19
by: linzhenhua1205 | last post by:
I want to parse a string like C program parse the command line into argc & argv. I hope don't use the array the allocate a fix memory first, and don't use the memory allocate function like malloc....
5
by: baskarpr | last post by:
Hi all, I my program after parsing in SAX parser, I want to write the parse result as an XML file. I want to ensure that there should be no difference between source XML file and parse result xml...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.