PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
klevis miho
Forum Contributor
Posts: 413 Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:
Post
by klevis miho » Tue Dec 15, 2009 10:27 am
I have this code:
Code: Select all
$findTd = '<td colspan="2">';
$start_td_pos = strpos($extract, $findTd); //73
$find_end_td = '</td></tr>';
$end_td_pos = strpos($extract, $find_end_td); //105
$length_grab1 = $end_td_pos - $start_td_pos;
$extract_hour_channel = substr($extract, $start_td_pos, $length_grab1);
echo $extract_hour_channel.'<br />'; //hour and name of the channel
But I want a loop to display all the strings that are inside $findTd and $find_end_td.
Any help would be appreciated
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Tue Dec 15, 2009 1:11 pm
What do the strings that are inside $extract, $findTd and $find_end_td look like? Examples please.
(#10850)
klevis miho
Forum Contributor
Posts: 413 Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:
Post
by klevis miho » Tue Dec 15, 2009 1:32 pm
$extract holds a large html file.
But I solved the thing, here is my code:
Code: Select all
while($i==0) {
$findTd = '<td colspan="2">';
$start_td_pos = strpos($extract, $findTd); //73
$find_end_td = '</td></tr>';
$end_td_pos = strpos($extract, $find_end_td); //105
$length_grab1 = $end_td_pos - $start_td_pos;
$value = substr($extract, $start_td_pos, $length_grab1);
echo $value.'<br />'; //hour and name of the channel
$start_new_extract = $end_td_pos + strlen($find_end_td);
$extract = substr($extract, $start_new_extract);
if(strstr($extract,$findTd)==FALSE) {
$i=1;
}
}
This finds all strings that are inside <td colspan="2"> </td>
AbraCadaver
DevNet Master
Posts: 2572 Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:
Post
by AbraCadaver » Tue Dec 15, 2009 1:56 pm
Not an answer to your original question, but...
Code: Select all
preg_match_all('#<td colspan="2">(.+?)</td>#s', $extract, $matches);
print_r($matches[1]);
mysql_function(): WARNING : This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
montyhar2
Forum Newbie
Posts: 3 Joined: Mon Dec 14, 2009 9:18 am
Post
by montyhar2 » Wed Dec 16, 2009 12:00 am
I will be try my beat into this code.I have need inside $findTd and $find_end_td string function.My code is here.
preg_match_all('#<td colspan="2">(.+?)</td>#s', $extract, $matches); And print_r($matches[1]);
I will also try this code.This is best solution.Thanks.
klevis miho
Forum Contributor
Posts: 413 Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:
Post
by klevis miho » Wed Dec 16, 2009 1:53 am
Thank you for your code AbraCadaver, will try it and give you my feedback
klevis miho
Forum Contributor
Posts: 413 Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:
Post
by klevis miho » Wed Dec 16, 2009 3:49 am
How can I print just the values?
klevis miho
Forum Contributor
Posts: 413 Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:
Post
by klevis miho » Wed Dec 16, 2009 7:41 am
With this code:
1. preg_match_all('#<td colspan="2">(.+?)</td>#s', $extract, $matches);
2. print_r($matches[1]);
you will get not just the things inside the td's but also the td's.
How can I just get the strings inside the td's?
AbraCadaver
DevNet Master
Posts: 2572 Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:
Post
by AbraCadaver » Wed Dec 16, 2009 8:56 am
$matches[0] contains the tds with values, $matches[1] contains just the values inside the tds.
mysql_function(): WARNING : This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
klevis miho
Forum Contributor
Posts: 413 Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:
Post
by klevis miho » Wed Dec 16, 2009 9:16 am
Thnx AbraCadaver it worked