Current location: Hot Scripts Forums » Programming Languages » PHP » file get contents

file get contents

Reply
  #1 (permalink)  
Old 11-17-09, 11:38 PM
vinpkl vinpkl is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 46
Thanks: 1
Thanked 0 Times in 0 Posts
file get contents

hi all

PHP Code:

<?php
$article 
file_get_contents('http://www.domain.com/article_eng.html');
$qry="insert into article_data (article) values('$aricle')";
$result=mysql_query($qry);
?>
with this function i can crawl my html page and fetch its content and add in database.

but i would like to know that my html page has

1) article title
2) author name
3) description

i dont want any images or any other data like nav, header, footer.

so how will i fetch these 3 things separately.

vineet
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-18-09, 12:15 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,702
Thanks: 0
Thanked 29 Times in 29 Posts
We would have to know how article_eng.html is setup in order to see how to get the
1) article title
2) author name
3) description


So, if you could show us the contents of
article_eng.html and explain where the above items are located in the document, then we may be able to show you how to get them.
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-18-09, 12:37 AM
vinpkl vinpkl is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 46
Thanks: 1
Thanked 0 Times in 0 Posts
file get contents

hi job0107

i have added a gif page layout for the article page.

pls have a look a suggest

vineet

Quote:
Originally Posted by job0107 View Post
We would have to know how article_eng.html is setup in order to see how to get the
1) article title
2) author name
3) description


So, if you could show us the contents of
article_eng.html and explain where the above items are located in the document, then we may be able to show you how to get them.
Attached Images
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-18-09, 08:19 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,702
Thanks: 0
Thanked 29 Times in 29 Posts
You don't understand, I can't go by pictures, I need to see the code.
The program needs to pull the information out of the code.

You see, article_eng.html displays the page using HTML.
HTML is made up of elements.
The elements can contain text, images, embedded sound, etc.

When you use file_get_contents(), you are extracting the code from the file.
In order to get specific items from the code, you need to know how the code is written.

Also, what creates
article_eng.html?
Do you have another program that creates
the article_eng.html file?
What I mean is, are other people submitting articles that are then converted into an HTML file?
Or are you creating the HTML file?
Is there more than one HTML file?
Or is there only one HTML file that displays different content that may be fetched from a database,
every time you view it?

Are you beginning to understand?

__________________
Jerry Broughton

Last edited by job0107; 11-18-09 at 08:33 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 11-18-09, 09:11 AM
vinpkl vinpkl is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 46
Thanks: 1
Thanked 0 Times in 0 Posts
file get contents

hi job0107

sorry if i was not able to clear the problem.

There are more than 2000 articles static html pages for which i need to extract data.

This is the sample code that i need to extract information from and add into database.

I need Title, Authorname, Article intro, articlebody as separate variables with information.

i hope this time everything will be understood.

vineet

Code:
<p class="title">article title</p>
<p class="authname">authorname</p>
<div class="articleintro">
<p>
article description come here article description come here article description come here article description come here article description come here article description come here article description come here article description come here 
</p>
</div>
<hr/>
<div class="articlebody">
<p>
article description come here article description come here article description come here article description come here article description come here article description come here article description come here article description come here 
</p>
<p>
article description come here article description come here article description come here article description come here article description come here article description come here article description come here article description come here 

</p>
<p>
article description come here article description come here article description come here article description come here article description come here article description come here article description come here article description come here 
</p>
<p>
article description come here article description come here article description come here article description come here article description come here article description come here article description come here article description come here 
</p>
</div>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 11-18-09, 11:17 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,702
Thanks: 0
Thanked 29 Times in 29 Posts
Quote:
Originally Posted by vinpkl View Post
hi job0107

sorry if i was not able to clear the problem.

There are more than 2000 articles static html pages for which i need to extract data.

This is the sample code that i need to extract information from and add into database.

I need Title, Authorname, Article intro, articlebody as separate variables with information.

i hope this time everything will be understood.

vineet

Code:
<p class="title">article title</p>
<p class="authname">authorname</p>
<div class="articleintro">
<p>
article description come here article description come here article description come here article description come here article description come here article description come here article description come here article description come here 
</p>
</div>
<hr/>
<div class="articlebody">
<p>
article description come here article description come here article description come here article description come here article description come here article description come here article description come here article description come here 
</p>
<p>
article description come here article description come here article description come here article description come here article description come here article description come here article description come here article description come here 

</p>
<p>
article description come here article description come here article description come here article description come here article description come here article description come here article description come here article description come here 
</p>
<p>
article description come here article description come here article description come here article description come here article description come here article description come here article description come here article description come here 
</p>
</div>
Providing ALL your pages are laid out exactly as you have described above,
and also providing you do not have anything against using a little javascript to assist,
then getting the contents becomes rather easy.

Instead of using file_get_contents(), I decided it would be easier to include your page in an invisible div.
Then have a javascript function capture the contents of the included document and store the results in a form.

Once the results are in the form, the form can be manually or automatically submitted for processing.

This example requires you to manually submit the form.
Then the value of the forms hidden input elements are displayed.
You could just as easily send the values to a database.
PHP Code:
<html>
<head>
<style>
.intro{color:#0a0;font-size:20px;font-weight:bold;}
span{color:#00f;font-size:20px;font-weight:bold;}
</style>
<script>
function getDocumentParts() {
 var temp = new Array();
 var elms = document.getElementsByTagName("p");
 for(var i = 0; i < elms.length; i++)
 {
  if(elms[i].className == "title"){temp[0] = elms[i].innerHTML;}
  if(elms[i].className == "authname"){temp[1] = elms[i].innerHTML;}
  }
 var elms = document.getElementsByTagName("div");
 for(var i = 0; i < elms.length; i++)
 {
  if(elms[i].className == "articleintro"){temp[2] = elms[i].innerHTML;}
  if(elms[i].className == "articlebody"){temp[3] = elms[i].innerHTML;}
  }
 document.getElementById("title").value = temp[0] ? temp[0] : "empty";
 document.getElementById("authname").value = temp[1] ? temp[1] : "empty";
 document.getElementById("articleintro").value = temp[2] ? temp[2] : "empty";
 document.getElementById("articlebody").value = temp[3] ? temp[3] : "empty";
}
</script>
</head>
<body onload="getDocumentParts()">
<div style="position:absolute;visibility:hidden;">
<?php
$fileName 
"article_eng.html";
include 
$fileName;
?>
</div>
<form action="#" method="POST">
<input type="hidden" id="title" name="title">
<input type="hidden" id="authname" name="authname">
<input type="hidden" id="articleintro" name="articleintro">
<input type="hidden" id="articlebody" name="articlebody">
<input type="submit" name="go" value="Show Contents">
</form>
<?php
if(!empty($_POST["go"]))
{
 echo 
"<span class='intro'>Providing all your pages are laid out exactly the same, then this program will work every time.</span><br />
       <span class='intro'>Here I am just displaying the contents of the variables. They could just as easily be sent to a database.</span><p>
       <span>Title: </span>"
.htmlspecialchars($_POST["title"])."<p><span>Author Name: </span>".htmlspecialchars($_POST["authname"])."<p><span>Artical Intro: </span>".htmlspecialchars($_POST["articleintro"])."<p><span>Artical Body: </span>".htmlspecialchars($_POST["articlebody"]);
 }
?>
</body>
</html>
__________________
Jerry Broughton

Last edited by job0107; 11-18-09 at 11:51 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to job0107 For This Useful Post:
vinpkl (11-19-09)
  #7 (permalink)  
Old 11-19-09, 01:21 AM
vinpkl vinpkl is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 46
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks job0107's

it works great. thanks for the solution.

vineet
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 11-19-09, 08:08 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,702
Thanks: 0
Thanked 29 Times in 29 Posts
Your welcome. Glad I could be of assistance.
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share 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
Hello all, can you help me? K4ot1K Other Languages 2 01-23-09 06:23 AM
running code against contents of a file? vbsaltydog Perl 7 09-27-06 05:11 PM
How to read contents of .doc file using file handling atulkul PHP 2 07-19-06 09:38 AM
compare the contents of 2 file in php rani PHP 5 04-15-04 12:47 AM
Displaying TEXT file contents to HTML tables Mendo PHP 2 02-18-04 12:19 PM


All times are GMT -5. The time now is 07:42 AM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.