How to transfer set of text from file to file using two identifiers using PHP? -


this code below can migrate 2 variables 1 file other.

<?php $file = 'somefile.txt'; // open file existing content $current = fopen($file,'a'); // append new person file $firstname .= "aiden\n"; $secondname .= "dawn\n"; $currentcontent = file_get_contents($file); // write contents file $filefound = 'people.txt'; $newfile = fopen($filefound,'a'); //if $current , $nextcurrent found in somefile.txt transfer content people.txt if (strpos($currentcontent,$firstname) !== 0) { if (strpos($currentcontent,$secondname) !== 0) {     fwrite($newfile, $currentcontent."\n");     } // endif }// endif ?> 

the next problem is, how able migrate texts identifier 1 identifiers two? guess i'll have use substr or strrpos string here. please :)

i'm having hard time understanding problem looks you're trying include between 'aiden' , 'dawn' file , write result new file.

give shot one

$firstidentifier = 'aiden'; $secondidentifier = 'dawn'; $currentcontent = str_replace("\n", "", file_get_contents('sourcefile.txt')); $pattern = '/('.$firstidentifier.')(.+?)('.$secondidentifier.')/';   //get text between 2 identifiers, , include identifiers in match result preg_match_all($pattern, $currentcontent , $matches);  //stick them space delimiter $contentofnewfile = implode(" ",$matches[0]);  //save new file $newfile = fopen('destinationfile.txt','a'); fwrite($newfile, $contentofnewfile); 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -