Jump to content

Search the Community

Showing results for tags 'fopen()'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 3 results

  1. hi I am trying to add a few line of code using fopen It works and it adds the lines but I have multiple occurrence of this line and I would like to all be amended. $target_line='$second = (int)substr($raw_date, 17, 2);'; $lines_to_add= '$raw_datetime = translate_from_gregorian($raw_datetime);'. PHP_EOL. '$year = (int)substr($raw_datetime, 0, 4);'. PHP_EOL. '$month = (int)substr($raw_datetime, 5, 2);'. PHP_EOL. '$day = (int)substr($raw_datetime, 8, 2);'. PHP_EOL; $config ='includes/functions/general.php'; $file=fopen($config,"r+") or exit("Unable to open file!"); $insertPos=0; // variable for saving //Users position while (!feof($file)) { $line=fgets($file); if (strpos($line,$target_line)!==false) { $insertPos=ftell($file); // ftell will tell the position where the pointer moved, here is the new line after //Users. $newline = $lines_to_add; } else { $newline.=$line; // append existing data with new data of user } } fseek($file,$insertPos); // move pointer to the file position where we saved above fwrite($file, $newline); fclose($file);
  2. So, I'm starting the book "PHP and MySQL Web Development 4th Edition" and have a question about some code from chapter 2. In the sample script you declare a variable $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; This is then used later when opening/creating a file for writing: @ $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab'); Unfortunately, it gives me an error saying the directory doesn't exist. Now if I eliminate the /.. part of the path it works fine. I seem to be having a reading comprehension problem as the text says ".." is used to mean "the parent directory of the document root directory" and I'm not entire sure what this means. Right now my orders folder is in the same folder as my script that executes this command: /Applications/XAMPP/xamppfiles/htdocs/processorder.php
  3. I'm still a little bit new to PHP, and I want to ammend the beginning of a text file, moving the previous content toward the end; reading around online the conensus I seem to be finding is that this is not possible with the functions as they are, so I plan to move the conents of a first 'master' file to a second 'hold' file, so I can then ammend the master file with the conents of the hold file afterward; however I'm not sure if it is possible to open two files at once; using some sample code I found online I hashed together this piece of code: /*******************/ /* WRITE TO FILE */ /*******************/ /*pass master news file to the hold file*/ flock($fq, LOCK_EX); //lock file fseek($fq,0); fwrite($fq, $fp, strlen($fp)); flock($fq, LOCK_UN); //unlock file fclose($fq); /*generate new news code*/ $date = date('jS F Y'); $outputstring = "<p><em class="newsheader">".$header."</em> - ".$date."\t"."<br>".$newsbody."</p><br>"; flock($fp, LOCK_EX); //lock file fseek($fp,0); fwrite($fp, $outputstring, strlen($outputstring)); flock($fp, LOCK_UN); //unlock file fclose($fp); echo '<p>News write successful</p>'; The master file is replaced fine, however, the hold file ends up containing "Resource id #1", is it not possible to hold open two files at once?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.