473,608 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can i parse this result

132 New Member
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 1407
computerfox
276 Contributor
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 New Member
how can i put the result in table to get each one
Jun 7 '15 #3
computerfox
276 Contributor
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 New Member
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 Contributor
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 New Member
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 Contributor
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
51388
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 class class Session { // Define the properties:
2
2880
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 process_card($card_details) { // connect to payment gateway or // use gpg to encrypt and mail or // store in DB if you really want to
1
2392
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 entire line from the file , headers as well > > >as just the desired body messages . > > > > > >fp = file("/home/chuck/pythonScript/testbox") > > >mb = mailbox.UnixMailbox(fp, > > >email.message_from_file)
2
1856
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 variable the output of bytesused variable is the below
22
872
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 tokenize the comma separated values.I used strtok function reading line by line using fgets.but it gives some weird behavior.It doesnot stripout the "" fully.Could any body have sample code for the same so that it will be helfful for my...
1
2014
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"> <loc>Newport</loc>
6
19021
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 submitting user information into my creation script, I get the following error from the page that is suppose to insert the user data into the database, create a code, then send an email out for verification. Parse error: parse error, unexpected $end in...
3
35072
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
20571
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. who can give me some ideas? The following is my program, but it has some problem. I hope someone would correct it. //////////////////////////// //Test_ConvertArg.c ////////////////////////////
5
3787
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 file. Because I set some properties in parser, which may cause to changes between actual and parsed. What I expect is the exact XML file structure is to be available into another XML file (incl white spc's) after SAX parsing. Below is a snippet...
0
8087
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8025
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8509
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8493
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6847
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3993
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4053
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1620
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.