944,091 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3638
  • PHP RSS
Sep 23rd, 2005
0

generating txt using php

Expand Post »
i have a problem in generating txt file from php. my prblem is After I add a news item etc. the script that updates the database would geneterate a text file. Then in my code instead of my 'include file show_news.php3' command, I would do a a include news.html that would be a pre-built html page. I think this would make the pages load faster. vs. making a bunch of mysql call each time a page is called. will u please help me
Similar Threads
Reputation Points: 11
Solved Threads: 0
Junior Poster
aarya is offline Offline
139 posts
since Sep 2005
Sep 23rd, 2005
0

Re: generating txt using php

my problem is i wnat my site to be like this
http://www.daniweb.com/techtalkforums/thread32816.html
actually it is working on php but working as html
Reputation Points: 11
Solved Threads: 0
Junior Poster
aarya is offline Offline
139 posts
since Sep 2005
Sep 23rd, 2005
0

Re: generating txt using php

I think the reason why people are not giving you answers is that it's not clear what your question is. We understand what you want to do, but we don't understand what you are having problems with.
Reputation Points: 38
Solved Threads: 25
Posting Shark
chrisbliss18 is offline Offline
902 posts
since Aug 2005
Sep 24th, 2005
0

Re: generating txt using php

ok i dont know how to do dynamic sites to static sites.
for example i have a real estate sites. the vistitors useses search engine to select resedential sites, he will get set of search list loction,type of land ext .and if person want to know details of that apartment he will click details.
this directs to details?listingid=26.php.
but i want details/26.html. i want in html but not php. i hope u have understood my problem
Reputation Points: 11
Solved Threads: 0
Junior Poster
aarya is offline Offline
139 posts
since Sep 2005
Sep 24th, 2005
0

Re: generating txt using php

it can be like this
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ashwinperti is offline Offline
22 posts
since Aug 2005
Sep 24th, 2005
0

Re: generating txt using php

Quote originally posted by aarya ...
i want in html but not php. i hope u have understood my problem
Once again. I understand what you are wanting to do, didn't ask any questions. I have actually built a site exactly like this many times (using Perl and MySQL) but didn't redirect to static pages. Redirecting to an html file rather than a php script isn't hard, but I think you are having more problems than just figuring out the redirect. Also, realize that the pages on this forum are not static files; rather, they are most likely html files with embedded PHP that the server parses before returning the file.

Ask questions. Seriously, we don't know what to help you with if we don't know what exactly it is that you don't know how to do.

If you don't know anything about how to make any parts of this program, then you are asking for a lot. I don't think anyone will design the entire project for you and then send you the source code.

If you are just hung up on some specifics, ask specific questions, such as: "How can I redirect out of a PHP script to another file on the site?"
Reputation Points: 38
Solved Threads: 25
Posting Shark
chrisbliss18 is offline Offline
902 posts
since Aug 2005
Sep 24th, 2005
0

Re: generating txt using php

aarya,

I would recommend that you purchase one of the following:

Professional LAMP

Beginning PHP, Apache, MySQL, Web Development

Core PHP Programming: Using PHP to Build Dynamic Web Sites



You seem to have quite a few questions, and this is a great place to start. However, you may want to take a more structured approach with this. That’s not meant to be offensive. It's just that one or more of these books may help bring you the structure you need as a novice, in this area, in a timely manner. You may find forums like this one more useful (a question here a question there that pops up, while you understand the underlying structure) after reading one of those books.
Reputation Points: 41
Solved Threads: 2
Junior Poster in Training
fsn812 is offline Offline
93 posts
since Jan 2004
Sep 27th, 2005
0

Re: generating txt using php

Hi aarya, :cheesy:

The question really is why you want to convert the php pages to static html files, and if it is necessary.

1) URL rewriting: The link you posted, though with an html extension, may actually be parsed by php. If this is the case, that means they are more concerned about Search Engine Friendly (SEF) urls than anything else.

2) PHP Cache: On the other hand they may very well be static html pages. If they are, then they may also be concerned about their server processing, and faster generation of the html page. (php will be slower to generate an html page).

In the case of this forum, (the link you posted above), it is most likely a SEF addon for VBulletin (this forum software) such as found here: http://www.vbulletin.org/forum/showthread.php?t=63314

If you're websites pages are very dynamic, like the real estate search listings page, you would probably want to use url rewriting (1).
Im not an expert, so I only know of the Apache Server methods of doing this.

You can rewrite the urls using mod_rewrite. Which is an apache module.
This is quite long to discuss here, but you can find alot of resources on the web.
Such as: http://www.sitepoint.com/article/sea...-friendly-urls

If your php page content does not change frequently, but you have alot of hits, and your server is slowing down, you can use a cache system (2).
A chache system, simple creates static html pages out of the php pages you have (but is more complicated then that).
Its discussed here: http://www.zend.com/zend/art/scriptcaching.php

What you can do is search the web for ready made open source scripts that do the job. They take care of a lot of problems that arise when you want to use these methods. (and automate alot of things, like changing all your links to point to the static files).

If you just want to know how to create an static html file from php, and are not concerned about the implementation. Its really simple:

[PHP]

// creates a local version of any url contents as html files
function cache_url($url, $cache_name, $cache_path = 'cache/') {

// this is simple the path to store the html file
$cache_abs_path = $cache_path.$cache_name;

// this opens an http connection to the url of your webpage
// search fopen at php.net
// you must supply a http path to this, so that we use the http wrapper and return only html
if (!$file = @fopen($url, 'r')) {
echo ('could not open the url: '.$url);
return false;
}

// this opens a file pointer to the html file you are saving too
// if the file doesnt exist, then it will attempt to create a new one
// you need the directory to have write permissions for the script
// chmod 777 (this can be done via ftp, or a web control panel, or php)
if (!$cache_file = @fopen($cache_abs_path, 'w+')) {
echo ('could not open the cache: '.$cache_abs_path.' for writing.');
return false;
}

// here we read the contents of the webpage
while($read = fread($file, '2082')) {

$content .= $read;

// we write the content of our webpage to the html file
if (!@fwrite($cache_file, $read)) {
echo ('error writing to cache: '.$cache_file.' for writing.');
return false;
}

}

// call the function like this
// here you will create a html page page_43.html in your pages directory.
// if you have the script in your webroot (http://mysite.com/) then the new page will be http://mysite.com/pages/page_43.html)

cache_url('http://mysite.com/page.php?id=43', 'page_43.html', 'pages');


[/PHP]

Good Luck.
www.digital-ether.com
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: problem with sessions
Next Thread in PHP Forum Timeline: storing details as html doc using php





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC