Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Lightbulb Urgent Help Needed on PHP Regex

    hi i am php newbie.i am trying to use preg_match_all function in the below program to find all subjects with their marks but i am getting only ONE match.i have been struggling with this for 5 hrs. can someone help me in figuring out whats wrong? thanks in advance

    PHP Code:
    <?php
    $semArray
    ="<B>STUDENTS NAME (6aa05cs001) </B><br><br><br><br><hr><table><tr><td><b>Semester:</b></td><td><b>2</b></td><td></td><td> &nbsp;&nbsp;&nbsp;&nbsp;<b> Result:&nbsp;&nbsp;FIRST CLASS </b></td></tr></table><hr><table><tr><td width=250>Subject</td><td width=60 align=center>External </td><td width=60 align=center>Internal</td><td align=center width=60>Total</td><td align=center width=60>Result</td></tr><br><tr><td width=250><i>Engineering Maths - II (06MAT21)</i></td><td width=60 align=center>51</td><td width=60 align=center>16</td><td width=60 align=center>67</td><td  width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Engineering Chemistry (06CHE22)</i></td><td width=60 align=center>40</td><td width=60 align=center>17</td><td width=60 align=center>57</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Computer Concepts and C Programming (06CCP23)</i></td><td width=60 align=center>70</td><td width=60 align=center>23</td><td width=60 align=center>93</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Computer Aided Engineering Drawing (06CED24)</i></td><td width=60 align=center>50</td><td width=60 align=center>16</td><td width=60 align=center>66</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Basic Electronics (06ELN25)</i></td><td width=60 align=center>42</td><td width=60 align=center>17</td><td width=60 align=center>59</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Computer Programming Lab (06CPL26)</i></td><td width=60 align=center>46</td><td width=60 align=center>24</td><td width=60 align=center>70</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Engg. Chemistry Lab (06CHEL27)</i></td><td width=60 align=center>41</td><td width=60 align=center>19</td><td width=60 align=center>60</td><td width=60 align=center><b>P</b></td></tr><tr><td width=250><i>Environmental Studies (06CIV28)</i></td><td width=60 align=center>48</td><td width=60 align=center>25</td><td width=60 align=center>73</td><td width=60 align=center><b>P</b></td></tr></table><br><br><table><tr><td></td><td></td><td>Total Marks:</td><td> 545 &nbsp;&nbsp;&nbsp; </td></tr></table>";
    function 
    get_result_for_this_sem($semArray)
    {

    preg_match("/Semester:<\/b><\/td><td><b>(.)<\/b>/",$semArray,$temp1);
    $sem_no=$temp1[1];
    preg_match("/Result:&nbsp;&nbsp;(.+)<\/b><\/td><\/tr><\/table><hr><table>/U",$semArray,$temp2);
    $sem_final_result=$temp2[1];
    preg_match_all("/<i>((.+?)\((.+?)\))<\/i><\/td><td width=60 align=center>([0-9]{1,3})<\/td><td width=60 align=center>([0-9]{1,2})<\/td><td width=60 align=center>([0-9]{1,3})<\/td><td  width=60 align=center><b>(.)<\/b><\/td><\/tr>/",$semArray,$temp3,PREG_SET_ORDER);

    print_r($temp3);

    }
    get_result_for_this_sem($semArray);
    ?>
    Here is the output that i get:
    Code:
    Array ( [0] => Array ( [0] => Engineering Maths - II (06MAT21)511667P  [1] => Engineering Maths - II (06MAT21) [2] => Engineering Maths - II [3] => 06MAT21 [4] => 51 [5] => 16 [6] => 67 [7] => P ) )
    Last edited by 1337c0d3r7001; 08-14-2010 at 06:04 PM.

  • #2
    Regular Coder
    Join Date
    Jul 2010
    Posts
    185
    Thanks
    3
    Thanked 42 Times in 42 Posts
    Use preg_match_all()

    preg_match() stops after the first match.

    Documentation:
    http://www.php.net/manual/en/functio...-match-all.php
    http://www.php.net/manual/en/function.preg-match.php

  • #3
    Regular Coder
    Join Date
    Jul 2010
    Posts
    185
    Thanks
    3
    Thanked 42 Times in 42 Posts
    Sorry, didn't notice you were using it for $temp3.

    I'll take a closer look this time

  • #4
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thank you very much for your replies

  • #5
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I got is resolved at stack overflow. it is actually a problem with the double space in the first subject's tags.

  • #6
    Regular Coder
    Join Date
    Jul 2010
    Posts
    185
    Thanks
    3
    Thanked 42 Times in 42 Posts
    Good to hear.

    I was just playing around with this:
    PHP Code:
    preg_match_all('@<tr><td width=250><i>(.+?)</i></td>(<td width=60 align=center>(.+?)</td>)+</tr>@',$semArray$strn,PREG_SET_ORDER); 

  • Users who have thanked disastro for this post:

    1337c0d3r7001 (08-14-2010)

  • #7
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That really did work. Thanks disastro for your time.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •