Hi I have to develop a code for file configuration in PHP.
My basic text file is stored in C:\abc
my text file name format is Mobile#_Code.request
Example: 923135470808_9033.request
Now I want to read code 9033 from the name of text file which always be there after _ and before .request
After getting code I will get data from MySQL DB and want to put this result in the form of message in the text file like "Hi 9033 your remaining balance is 50USD"
Now after putting message in same file I want to rename the file name as 923135470808_9033.done
means request changes in done.

please guide me.
Thanks

So, you want to get information from a txt file? am I right? if so, try using the

parse_ini_file()
to read from the txt file.

do something like

;in the config file

[request]
923135470808_9033

//in php

$ini_array = parse_ini_file("Mobile#_Code.ini");

//go here for more http://php.net/manual/en/function.parse-ini-file.php

ps: yellow background and white fonts may not be the most READABLE approach

I cant understand this by you
I have written this code for this but have some problems

<?php
include("config.php");
$dirname = "./abc";
$dir = opendir($dirname);
while(false != ($file = readdir($dir)))
{
if(($file != ".") and ($file != ".."))
{
echo("$file <br />");
$fileN = basename("./abc/$file", ".request.txt"); // $file is set to "index"
echo $fileN;
echo "<br />";
echo $Code=substr($fileN,13);
echo "<br />";
$result = mysql_query("SELECT Code,BaseAmount from lims_payment Where Code='$Code'");
$row = mysql_fetch_array($result);
echo $sms="Your cheque amount of " . $row[1] . " is ready in Regional office";
 $file2= fopen("./abc/$file","w") or die ("Error opening file in write mode!");    
fputs($file2,$sms); 
fclose($file2) or die ("Error closing file!"); 
//rename("./abc/$file", "./abc/1234.txt");
}
}

?>

Now I want to rename as written in step 5 in my attached immage any one guide how to rename part of file.

How I can change 923135470808_9033.request test file name to 923135470808_9033.done using PHP Code.

my problem solved i used string replace for renaming file name after puting text in it

its solved

<?php
include("config.php");
$dirname = "./abc";
$dir = opendir($dirname);
while(false != ($file = readdir($dir)))
{
if(($file != ".") and ($file != "..") and (substr($file,18)=="request") )
{
$fileN = basename("./abc/$file", ".request"); // $file is set to "index"
echo $fileN;
echo "<br />";
echo $Code=substr($fileN,13);
echo "<br />";
$r = mysql_query("SELECT Code from lims_payment Where Code='$Code'");
$num_rows = mysql_num_rows($r);
if($num_rows > 0)
{
$result = mysql_query("SELECT SiteId,Year(DurationS),pDate,cDate,Reasons from lims_payment Where Code='$Code' Order by DurationS DESC");
$row = mysql_fetch_array($result);

echo $sms="SiteId: " . $row[0] . "   Year: " . $row[1] . "   Processed Date: " . $row[2] . "   Cheque Issued Date: " . $row[3] . "   Status: " . $row[4] . "";
 $file2= fopen("./abc/$file","w") or die ("Error opening file in write mode!");    
fputs($file2,$sms); 
fclose($file2) or die ("Error closing file!");
//rename file name
$doneN = str_replace("request", "done", $file);
echo $doneN;
rename("./abc/$file", "./abc/$doneN");
}
else
{
$sms = "Please contact Yasin Zakir 03135565656 Or Ehasn Bari 03125604933 for Further Help.";
 $file2= fopen("./abc/$file","w") or die ("Error opening file in write mode!");    
fputs($file2,$sms); 
fclose($file2) or die ("Error closing file!");
//rename file name
$doneN = str_replace("request", "done", $file);
echo $doneN;
rename("./abc/$file", "./abc/$doneN");
}

}
}

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.