The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Remove parts of an html output and convert rest to variables?
Discuss Remove parts of an html output and convert rest to variables? in the PHP Development forum on Dev Shed. Remove parts of an html output and convert rest to variables? PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 17th, 2013, 10:04 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 1 h 27 m 28 sec
Reputation Power: 0
|
|
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">5 </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">5 </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">5 </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
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 ($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "avatarname=HIDDEN&password=HIDDEN");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$store = curl_exec ($ch);
curl_setopt($ch, CURLOPT_URL, "http://imvu.com/catalog/web_credits_balance_log.php");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
$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
|

January 17th, 2013, 10:06 AM
|
|
|
|
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.
|

January 17th, 2013, 10:09 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 1 h 27 m 28 sec
Reputation Power: 0
|
|
|
i have updated OP with my php code
|

January 17th, 2013, 10:15 AM
|
|
|
|
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.
|

January 17th, 2013, 10:19 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 1 h 27 m 28 sec
Reputation Power: 0
|
|
$matches is the output that comes out when it only keep the html code from
Code:
<!--end widget_pagination-->
to
Best Regards Xkay
|

January 17th, 2013, 10:24 AM
|
|
|
|
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.
|

January 17th, 2013, 10:26 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 1 h 27 m 28 sec
Reputation Power: 0
|
|
Quote: | 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
|

January 17th, 2013, 10:35 AM
|
|
|
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.
|

January 17th, 2013, 10:37 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 1 h 27 m 28 sec
Reputation Power: 0
|
|
Okay thank you, i will try that
Best Regards Xkay
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|