» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > PHP Programming and Tips

PHP Programming and Tips Discuss about PHP programming and Share Tips. Ask questions about Scripting and Errors.

Reply
 
Thread Tools Display Modes
  #1  
Old 08-10-2006, 02:48 PM
navy navy is offline
OSP Starters
 
Join Date: Jul 2006
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
Rep Power: 0
navy is on a distinguished road
Cool replacing contents of a text file

Hi

Code:
<html>
<head>
<title>My Title</title>
<meta.................
..........................
</head>

</bod>
Some texts
</body>
</html>

Now I want to replace the lines between <head> and </head>.

I know how to replace a pattern in the text file. But How can I replace the contents between two patterns.

Thnx -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 08-10-2006, 02:49 PM
anastasia anastasia is offline
OSP Starters
 
Join Date: Mar 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
anastasia is on a distinguished road
Default

Try this code

define ('DATA_FILE', 'c:\myfile.txt');

if (!file_exists(DATA_FILE))
{
die ('File not found: '.DATA_FILE);
}

$data = file_get_contents(DATA_FILE);
$replacementText = 'HERE GOES THE HEADER';

$data = preg_replace('/<head>(.*)<\/head>/msiU', $replacementText, $data);

$fd = fopen('w+', DATA_FILE);
fwrite($fd, $data);
fclose($fd);

Best of luck -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Free File Storage Hosts vishnuthegreat Domains For Sale - Fixed Price/Offer 1 03-06-2007 09:31 AM
Convert text file into .MYD fille and .....!! Symah MySQL Forums 1 11-06-2006 05:05 AM
Now google can read text in Flash file? symonds Google 4 08-29-2006 12:23 PM
text file into textfile nirvana ASP forums and Tips 1 07-31-2006 05:57 PM
text file.... bono ASP forums and Tips 1 07-30-2006 12:47 PM


All times are GMT. The time now is 08:54 AM.