Reply
How to grab everything between two tags... not working grr
Old 06-28-2008, 05:57 PM How to grab everything between two tags... not working grr
dansgalaxy's Avatar
Eat, Sleep, Code

Latest Blog Post:
Offending facebook ads… so?
Posts: 6,096
Name: Dan
Location: Swindon
Okay, so i have spent god knows how long trying to figure this out, with the help of someone else and i still cant make it work and im at the point of insanity.

okay so the code i have:
PHP Code:
<?php 
$user 
'dan'
$pass '******'
$url 'xdnet.co.uk';//do not include 'http://' 
$page file_get_contents("http://$user:$pass@$url:2082/frontend/x3/status.html"); 
//$int = preg_match("/<table border=2>.*<\/table>/is",$page, $match);
$pattern "#\<table\>(.+?)</table\>#ie";
$int preg_match($pattern$page$match); 
echo 
count($match);
echo 
$match[0];
 
?>
basically it should get the page (which it does fine) and then just show the table.


but it dont.

$match is empty and $int returns false (0)

so what the *bleeping* is wrong with it! >< GUH!!!! I HATE REGEX!

All the TP i can give for a working answer!
*bloodshot twitchy eyes*

Dan
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
When You Register, These Ads Go Away!
     
Old 06-28-2008, 10:23 PM Re: How to grab everything between two tags... not working grr
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Wireless Audio
Posts: 2,314
Name: Keith Marshall
Location: West Hartford, CT
Is it possible to show the html that is returned from the page?
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 06-28-2008, 10:51 PM Re: How to grab everything between two tags... not working grr
Extreme Talker

Posts: 235
Location: United States
Quote:
Originally Posted by dansgalaxy View Post
PHP Code:
 $pattern "#\<table\>(.+?)</table\>#ie"
To begin with, a couple of minor issues: first, the brackets (< and >) don't need to be escaped. It won't break your regexp if you do use them, though. Second, the "e" modifier at the end of the pattern is ignored for a preg_match(). I can't remember what it does, but I do know it's only used for preg_replace().

By default, in preg_whatever functions, a . will match all characters EXCEPT newlines. So if this table that you are trying to scrape has a newline anywhere in it, this regexp will not match it. The solution is to add the "s" modifier to the end of the pattern.

Try:
PHP Code:
$pattern "#<table>(.+?)</table>#is"
Hopefully that fixes it.

EDIT: I'm going to sneak an edit in here because I just realized that the brackets (< and >) can have a special meaning in regex, and I don't want someone to read this later and leave with false info. Regex is so complicated!

Last edited by frost : 07-01-2008 at 01:45 AM. Reason: Factual mistake. Oops.
frost is offline
Reply With Quote
View Public Profile
 
Old 06-29-2008, 10:59 AM Re: How to grab everything between two tags... not working grr
dansgalaxy's Avatar
Eat, Sleep, Code

Latest Blog Post:
Offending facebook ads… so?
Posts: 6,096
Name: Dan
Location: Swindon
okay, thanks frost tried it no such luck

http://xdnet.co.uk/status.php <- the file

(note the extra 0 on there is because i am also echoing $int)

you can view the html page here: http://xdnet.co.uk/cpanel_status.php this is using a simple file_get_contents without trying to edit the returned page... so u can se it all

This really is doing my nut in now, i thought i could just find a snippet on google and dump it in and be done! surly SOMEONE other than me has wanted to do this before?!

Thanks all,
Dan
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 06-29-2008, 11:11 AM Re: How to grab everything between two tags... not working grr
dansgalaxy's Avatar
Eat, Sleep, Code

Latest Blog Post:
Offending facebook ads… so?
Posts: 6,096
Name: Dan
Location: Swindon
YAY this seems to work!

PHP Code:
$pattern "#<table.*/table>#is"
*skips off merrily*
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to How to grab everything between two tags... not working grr
 

Thread Tools

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13520 seconds with 13 queries