Current location: Hot Scripts Forums » Programming Languages » PHP » Read a HTML page from PHP


Read a HTML page from PHP

Reply
  #1 (permalink)  
Old 09-15-05, 05:10 PM
fox1999 fox1999 is offline
New Member
 
Join Date: Sep 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Read a HTML page from PHP

Hi all,

i have a PHP page on my site. I need to read a HTML page of another site and analyze the contents to search some strings.

What functions i have to use? Someone can suggest me the code to do this?

Thanks in advance

Flavio

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-15-05, 05:52 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
There are two easy ways to do this. You could use file() or file_get_contents():

PHP Code:

// Reads entire HTML contents into the string

$html file_get_contents('http://www.domain.com/page.html');

// Print source
echo $html;


// OR //


// Splits the HTML contents into an array by line
$html file('http://www.domain.com/page.html');

// Print source
foreach ($html as $key => $value)
echo 
$value "\n"
Once you have the code asigned to the variable, there are plenty of regular expressions that can parse the code however you like.

Last edited by Keith; 09-15-05 at 05:54 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-15-05, 08:17 PM
shadi's Avatar
shadi shadi is offline
Wannabe Coder
 
Join Date: Aug 2004
Location: EGY
Posts: 145
Thanks: 0
Thanked 0 Times in 0 Posts
also , you should give fsockopen a try

http://www.php.net/manual/en/function.fsockopen.php
__________________
Email : write2shadi at gmail dot com
MSN : write2shadi at gmail dot com
Aim : shadiaim7
Skype: shadi_skype
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 09-16-05, 10:02 AM
wheezy360's Avatar
wheezy360 wheezy360 is offline
Newbie Coder
 
Join Date: Nov 2003
Location: Toronto, ON
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
As well, you must have allow_url_fopen enabled in your php.ini to open remote files.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 09-16-05, 12:16 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
This would be pretty easy to do with cURL, about a dozen lines or so.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
html tutoral thefrtman HTML/XHTML/XML 5 04-27-09 11:25 AM
Classified Ads skipper23 Perl 3 11-22-05 03:22 AM
Putting PHP into a HTML page? PigeonHead HTML/XHTML/XML 5 01-24-05 03:22 PM
php on a html page Bonzo PHP 9 02-06-04 11:40 PM
Classified Ads skipper23 Perl 2 12-30-03 04:43 AM


All times are GMT -5. The time now is 10:05 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.