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
Change contents of a text file?
Old 01-02-2006, 05:13 AM Change contents of a text file?
Junior Talker

Posts: 2
Trades: 0
Hi,
I am building a web site and have all the text titles in a file called texts.php and I want to be able to add new texts a the end of file one line before the ?>.

so:
How can I read all the file?
Remove the ?> from the end of the file?
writing new line(s) at the end of the file?
Adding new ?> at the end again

here is the file:

<?php
// main texts December 25, 2005


$lang['sitename']= 'MySite.com';
$lang['siteurl']= 'http://mysite.com';

$lang['click_here']='Click Here';
?>

=========================================
here is what I have done:
This file can read but I can't get the contents outside this code and use somewhere else in a function:
$repl="\n";
$special = "\?>";

$handle = @fopen("$myfile", "r") or die("can not find the file to read");
while (!feof($handle)) {
$buffer = fgets($handle, 4096);

//echo $buffer ;
$samm =ereg_replace($special,$repl, $buffer);

echo $samm;

}// end of while
fclose($handle);

I can get the contents within the while { .....} only.
Please help.
Bacha is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-02-2006, 09:23 AM
Skilled Talker

Posts: 68
Trades: 0
Well explain what your doing, and why dose this file have to have <? and ?> tags around it? thers prob a easyer way to do what you need to do.
mrpaul is offline
Reply With Quote
View Public Profile
 
Old 01-02-2006, 01:41 PM
Junior Talker

Posts: 2
Trades: 0
Quote:
Originally Posted by mrpaul
Well explain what your doing, and why dose this file have to have <? and ?> tags around it? thers prob a easyer way to do what you need to do.
this is an include file as "mytext.php" or "mytext.txt" where it helds all the texts tags for the web site I want to the same as it is done in "phpbb" forum where the text are in anoth file so in the future update I only open the file that has the text.

in that file I havve
$lang['sitename']='Webmaster Talk For All';

and this file (the file that contains texts) is used as include in all of my php files and simply when I want to print that text I do:
echo $lang['sitename'];
and it prints the text.
can you suggest anything else?
I though to use mysql to hold the text but I think it may be slower that way.
Regards
Bacha is offline
Reply With Quote
View Public Profile
 
Old 01-05-2006, 01:47 PM
Skilled Talker

Posts: 68
Trades: 0
Well you could prob use
PHP Code:
$old str_replace("?>"" "$buffer); 
so that replaces ?> with blank text, then all that needs to be done is write $old and some otehr data, say new? to a file - finaly write ?> to the end.
PHP Code:
$filename "File.txt";           # sets file name.
$handle fopen($filename"r"); # opens the file to read it.

$old fread($handlefilesize ($filename)); # $old is now the text in $filename

fclose($handle); #closes file.  #close file
$new " The new stuf ";   # the new stuff to be writen is here.
$old2 str_replace("?>"" "$old); # $old2 is the same as old without the ?>
$tag = "?>"; 
$final_content = $old2.$new.$tag; #Finaly every is set to be writen


$handle2 = fopen($filename, "w");  #opens it
$finalwrite = fwrite($handle2, $final_content); #writes it
fclose($handle2); #closes it 
Remove all the anoying #things and it should work.

Last edited by mrpaul; 01-05-2006 at 01:50 PM..
mrpaul is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Change contents of a text file?
 

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