Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Using PHP to generate html files using variables
Old 09-04-2007, 01:56 AM Using PHP to generate html files using variables
Extreme Talker

Posts: 150
Trades: 0
i'm using this script to create / generate a new .html file and it works fine, but....

// MAKE FILE indes.html
$filename = "index.html";
$fp = fopen($filename,"w") or die ("Error Opening File");
fputs($fp,$content);
fclose($fp);

...now i want to replace the "index" with any variable ie: $varname

$varname = "newname";
$filename = "$varname.html";
$fp = fopen($filename,"w") or die ("Error Opening File");
fputs($fp,$content);
fclose($fp);

it should generate the file newname.html but it's not working, can someone please let me know how to make this work?
archyboy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-04-2007, 02:15 AM Re: Using PHP to generate html files using variables
Experienced Talker

Posts: 44
Name: Kuldeep Sahi
Trades: 0
Try replacing the following line:

$filename = "$varname.html";

with:

$filename = $varname . ".html";

Also echo $filename to check whether the filename is created correctly.
__________________

Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE
Kuldeep2195 is offline
Reply With Quote
View Public Profile Visit Kuldeep2195's homepage!
 
Old 09-04-2007, 02:34 AM Re: Using PHP to generate html files using variables
metho's Avatar
Ultra Talker

Posts: 481
Location: Gold Coast - Brisbane QLD, Australia
Trades: 0
This works huh?

PHP Code:
// MAKE FILE index.html
$filename "index.html";
$fp fopen($filename,"w") or die ("Error Opening File");
fputs($fp,$content);
fclose($fp); 
Then you want to "..replace the 'index' with any variable ie: $varname"?

In other words, rename index.html to a variable's value?

PHP Code:

$current_filename 
$filename;
$new_name 'renamed_index';
$new_filename $new_name '.html';

if(@
is_writable($current_filename))  {

  
rename($current_filename,$new_filename);

} else {

  die (
"File $current_filename is not writable or does not exist.");


__________________
I do
Please login or register to view this content. Registration is FREE
based.
Spend a lot of time in
Please login or register to view this content. Registration is FREE
.
And
Please login or register to view this content. Registration is FREE
chews up the rest.

Last edited by metho; 09-04-2007 at 02:37 AM.. Reason: is_writable is a better test than file_exists
metho is offline
Reply With Quote
View Public Profile Visit metho's homepage!
 
Old 09-04-2007, 03:57 AM Re: Using PHP to generate html files using variables
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
yea that script seems a bit weird, whats the point in opening it and then closing it with out actually touching the content of index, and then doing soemthign to the file name.
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 04-25-2009, 04:44 AM How can anyone make his or hers website in the top of the search engine result
frorryill's Avatar
Junior Talker

Posts: 1
Trades: 0
Good afternoon

The more links your website receives over time, the higher it’s pagerank will prove be

Pay attention to keyword density, title descriptions, meta tags, alt tags and interior linking structure.

Use off-page optimization for your major keywords.

why it is adviced to keep less links in a high PageRank page so that the link would be more valuable

I can’t begin to say enough about how I appreciate goowall.com advertising service.
__________________
Jaws
Please login or register to view this content. Registration is FREE
frorryill is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Using PHP to generate html files using variables
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 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.66066 seconds with 12 queries