Hi guys, I'm new to php but this what I'm looking to accomplish.
I want php to open a file which has contents like below:
@340
0101
1010
1111
0000
1100
0011
0110
1001
What I want php to do is to look at the file, find the first '@' then pass whatever is after it on that line to a variable.
Then I want it to take every two lines after that and convert it to one line and send it to a variable
So variable1 =01011010
It would keep doing this until it reached another '@'. Then it would repeat the process over again... can anyone help me out?
Thanks a lot! I hope i made sense!!
-Nick
Php file handling
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Php file handling
Hi
all, I need the same funtionality, But i want to access the txt file which has html codes.
The below codes works fine for any txt files which do not have the html codes by using fgets(), but do not work for html code.
I have also used fgetss() so that it parse for html code
Pls help.
<?php
?>
<html>
<head>
<title>Using fscanf with Optional Variables</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<p>
<?php
//output file where i want the desired string
$logFile = "output.txt";
//First string Condition
$nametag="<listed business name>\r\n";
//Second string Condition
$nametag1="<td>\r\n";
//Alabama.txt is the input file i want to read from
if (!($fp = fopen("Alabama.txt", "r")))
exit("Unable to open the input file.");
while (!feof($fp))
{
$buffer = fgets($fp, 1024);
if (strcmp($nametag, $buffer) == 0)
{
while (!feof($fp))
{
//echo "hi";
$buffer1 = fgets($fp, 1024);
// print $buffer1;
$fp1= fopen("$logFile","a");
fwrite($fp1, "$buffer1");
if (strcmp($nametag1, $buffer1) == 0)
break;
}
fclose($fp1);
}
}
//print "$buffer<br>\n";
fclose($fp);
?>
</p>
</body>
</html>
all, I need the same funtionality, But i want to access the txt file which has html codes.
The below codes works fine for any txt files which do not have the html codes by using fgets(), but do not work for html code.
I have also used fgetss() so that it parse for html code
Pls help.
<?php
?>
<html>
<head>
<title>Using fscanf with Optional Variables</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<p>
<?php
//output file where i want the desired string
$logFile = "output.txt";
//First string Condition
$nametag="<listed business name>\r\n";
//Second string Condition
$nametag1="<td>\r\n";
//Alabama.txt is the input file i want to read from
if (!($fp = fopen("Alabama.txt", "r")))
exit("Unable to open the input file.");
while (!feof($fp))
{
$buffer = fgets($fp, 1024);
if (strcmp($nametag, $buffer) == 0)
{
while (!feof($fp))
{
//echo "hi";
$buffer1 = fgets($fp, 1024);
// print $buffer1;
$fp1= fopen("$logFile","a");
fwrite($fp1, "$buffer1");
if (strcmp($nametag1, $buffer1) == 0)
break;
}
fclose($fp1);
}
}
//print "$buffer<br>\n";
fclose($fp);
?>
</p>
</body>
</html>