PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 17th, 2013, 10:04 AM
Xkay Xkay is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 Xkay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 28 sec
Reputation 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

Reply With Quote
  #2  
Old January 17th, 2013, 10:06 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,885 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 17 m 9 sec
Reputation Power: 581
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.

Reply With Quote
  #3  
Old January 17th, 2013, 10:09 AM
Xkay Xkay is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 Xkay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 28 sec
Reputation Power: 0
i have updated OP with my php code

Reply With Quote
  #4  
Old January 17th, 2013, 10:15 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,885 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 17 m 9 sec
Reputation Power: 581
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.

Reply With Quote
  #5  
Old January 17th, 2013, 10:19 AM
Xkay Xkay is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 Xkay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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
Code:
<!-- pi_header-->


Best Regards Xkay

Reply With Quote
  #6  
Old January 17th, 2013, 10:24 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,885 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 17 m 9 sec
Reputation Power: 581
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.

Reply With Quote
  #7  
Old January 17th, 2013, 10:26 AM
Xkay Xkay is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 Xkay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #8  
Old January 17th, 2013, 10:35 AM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,885 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 17 m 9 sec
Reputation Power: 581
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.

Reply With Quote
  #9  
Old January 17th, 2013, 10:37 AM
Xkay Xkay is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 Xkay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 28 sec
Reputation Power: 0
Okay thank you, i will try that

Best Regards Xkay

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Remove parts of an html output and convert rest to variables?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap