#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Question Remove parts of an html output and convert rest to variables?


    So i was referred to this forum by a mate, and i hope you can help me to solve my little problem.

    How can i remove parts of this HTML i get from my cURL output.
    PHP Code:
    <body><table border="0" width="100%" cellspacing="0" cellpadding="5">
    <
    tbody><tr class="tableHeader">
    <
    td align="center" rowspan="2">Date</td>
    <
    td align="right" rowspan="2">Amount</td>
    <
    td align="center" colspan="2">Credits</td>
    <
    td align="center" colspan="2">Promo Credits</td>
    <
    td align="center" class="reason" rowspan="2">Reason</td>
    </
    tr>
    <
    tr class="tableHeader" align="center">
    <
    td>Before</td>
    <
    td>After</td>
    <
    td>Before</td>
    <
    td>After</td>
    </
    tr><tr class="tableContent">
    <
    td align="center" bgcolor="#FFFFFF">2013-01-17 07:18:46 </td>
    <
    td align="right" bgcolor="#FFFFFF">-10 </td>
    <
    td align="right" bgcolor="#FFFFFF">41,016 </td>
    <
    td align="right" bgcolor="#FFFFFF">41,006 </td>
    <
    td align="right" bgcolor="#FFFFFF">2,109 </td>
    <
    td align="right" bgcolor="#FFFFFF">2,109 </td>
    <
    td align="left" bgcolor="#FFFFFF">Web gift to user 92314863 </td>
    </
    tr><tr class="tableContent">
    <
    td align="center" bgcolor="#DDDDDD">2013-01-17 07:20:13 </td>
    <
    td align="right" bgcolor="#DDDDDD"></td>
    <
    td align="right" bgcolor="#DDDDDD">41,006 </td>
    <
    td align="right" bgcolor="#DDDDDD">41,011 </td>
    <
    td align="right" bgcolor="#DDDDDD">2,109 </td>
    <
    td align="right" bgcolor="#DDDDDD">2,109 </td>
    <
    td align="left" bgcolor="#DDDDDD">Web gift from user 92314863 </td>
    </
    tr><tr class="tableContent">
    <
    td align="center" bgcolor="#FFFFFF">2013-01-17 07:20:40 </td>
    <
    td align="right" bgcolor="#FFFFFF"></td>
    <
    td align="right" bgcolor="#FFFFFF">41,011 </td>
    <
    td align="right" bgcolor="#FFFFFF">41,016 </td>
    <
    td align="right" bgcolor="#FFFFFF">2,109 </td>
    <
    td align="right" bgcolor="#FFFFFF">2,109 </td>
    <
    td align="left" bgcolor="#FFFFFF">Web gift from user 92314863 </td>
    </
    tr></tbody></table><br><div class="pi_header"><font size="-1">Download this report in <a href="/catalog/web_credits_balance_log.php?output=xml"><img src="/catalog/img/xml.gif" border="0"></a> or <a href="/catalog/web_credits_balance_log.php?output=csv">CSV</a></font></div><font size="-1"> <!-- pi_header--></font></body
    So i only get the area where it post:
    Code:
    Web gift from user 92314863
    Note that the site it pull the data from i dynamic, and this part:
    PHP Code:
    <tr class="tableContent">
    <
    td align="center" bgcolor="#DDDDDD">2013-01-17 07:20:13 </td>
    <
    td align="right" bgcolor="#DDDDDD"></td>
    <
    td align="right" bgcolor="#DDDDDD">41,006 </td>
    <
    td align="right" bgcolor="#DDDDDD">41,011 </td>
    <
    td align="right" bgcolor="#DDDDDD">2,109 </td>
    <
    td align="right" bgcolor="#DDDDDD">2,109 </td>
    <
    td align="left" bgcolor="#DDDDDD">Web gift from user 92314863 </td>
    </
    tr
    Can be repeated up to 50 times.

    The number is changing for each different users ID.
    I know how to remove
    Code:
    Web gift from user
    But how can i make the number into an variable if there are more than one, as showed in the demo code.

    My php code
    PHP Code:
    <?php
    $headers 
    = array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8) Gecko/20061025 Firefox/1.5.0.8");
    $target_url "http://imvu.com/catalog/web_credits_balance_log.php?output=xml";
    $url="https://da.secure.imvu.com/login/";
    $ch curl_init();
    curl_setopt ($chCURLOPT_COOKIEJAR'cookies.txt');
    curl_setopt($chCURLOPT_COOKIEFILE'cookies.txt');
    curl_setopt($chCURLOPT_URL$url);
    curl_setopt ($chCURLOPT_POST1);
    curl_setopt ($chCURLOPT_POSTFIELDS"avatarname=HIDDEN&password=HIDDEN");
    curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
    curl_setopt ($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_VERBOSE1);
    curl_setopt($chCURLOPT_HTTPHEADER$headers);
    curl_setopt($chCURLOPT_MAXREDIRS4);
    curl_setopt($chCURLOPT_SSL_VERIFYPEERFALSE);
    $store curl_exec ($ch);
    curl_setopt($chCURLOPT_URL"http://imvu.com/catalog/web_credits_balance_log.php");
    curl_setopt($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0");
    curl_setopt($chCURLOPT_HEADERfalse);
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
    curl_setopt($chCURLOPT_MAXREDIRS10);
    $output curl_exec($ch);
    preg_match('/<!--end widget_pagination-->(.*)<!-- pi_header-->/is'$output$matches); 
    echo 
    $matches[0]; // Show me echo
    curl_close($ch);



    ?>
    Best Regards Xkay
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,453
    Rep Power
    594
    What have you tried? Where is your PHP code? A simple array seems like what you are asking for.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    i have updated OP with my php code
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,453
    Rep Power
    594
    So what is $matches and what exactly are you trying to get into a variable?

    P.S. Please enclose your code in [ PHP ] tags. See the sticky at the top of this forum.
    Last edited by gw1500se; January 17th, 2013 at 10:19 AM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    $matches is the output that comes out when it only keep the html code from
    Code:
    <!--end widget_pagination-->
    to
    Code:
    <!-- pi_header-->
    Best Regards Xkay
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,453
    Rep Power
    594
    OK, so you need to parse the html and extract the indicated text. Then extract the number from that text into a variable. Correct? Which part is giving you trouble. You did not post the code that does that.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by gw1500se
    OK, so you need to parse the html and extract the indicated text. Then extract the number from that text into a variable. Correct? Which part is giving you trouble. You did not post the code that does that.
    Yes that is correct, and that is giving me troubles :i

    Best Regards Xkay
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,453
    Rep Power
    594
    There are a couple of ways depending on if similar strings appear in the html that you want to exclude. The best way to extract exactly what you want is to use DOM. If the string indicated is always what you want then you can use a loop to find each occurrence with strpos and substr and extract each number into an array.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Okay thank you, i will try that

    Best Regards Xkay

IMN logo majestic logo threadwatch logo seochat tools logo