Click here to Skip to main content
15,887,596 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
AnswerRe: i catch a problem when i compiling Pin
Iranian MM8-Sep-11 5:30
Iranian MM8-Sep-11 5:30 
Questionproblem in windows 7 Pin
mstanwar13-Oct-10 14:46
mstanwar13-Oct-10 14:46 
AnswerRe: problem in windows 7 Pin
Mohamed7IBrahim18-Nov-10 3:48
Mohamed7IBrahim18-Nov-10 3:48 
GeneralRe: problem in windows 7 Pin
Ali Al Omairi(Abu AlHassan)13-Feb-11 14:50
professionalAli Al Omairi(Abu AlHassan)13-Feb-11 14:50 
QuestionPHP File Open and Reading character by character Pin
nathionice13-Oct-10 5:33
nathionice13-Oct-10 5:33 
AnswerRe: PHP File Open and Reading character by character Pin
cjoki14-Oct-10 4:44
cjoki14-Oct-10 4:44 
RantRe: PHP File Open and Reading character by character Pin
Macotti20-Oct-10 0:59
Macotti20-Oct-10 0:59 
GeneralRe: PHP File Open and Reading character by character Pin
cjoki20-Oct-10 5:00
cjoki20-Oct-10 5:00 
the php function defines for reference.
--------- fopen function....
resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )

--------- explode function....
array explode ( string $delimiter , string $string [, int $limit ] )

--------- foreach looping construct....
foreach (array_expression as $value)
statement
foreach (array_expression as $key => $value)
statement

now step through his code....
$output=fopen("testfile.txt","r") or exit("Unable to open file!"); <--- $output is a file resource, this is not the file content.

//(2) Then we can get rid of the"," in there:
$output = str_replace(","," ", $output); <--- he takes the $output which is a file resource and does a string replace on it and re-assigns the variable $output as a string.
//(3) Then we explode it at every ,encountered
//$output = explode(",",$output); <--- when this is uncommented it will change a string into an array. If the source string has no "commas" in it it will return an array with one value. you could also say if(count($output)==1)) {echo "I have 1!";}else{echo "I'm Lost!";}, but currently it does nothing as it is commented out so $output should still be a string.
echo "output"; <--- echos a string called "output"
echo $output; <--- echoes a variable currently a string and most likely just the name of the file resource returned from the fopen call.
foreach($output as $var) <--- in a foreach the first argument MUST be an array!, it is a string right now and so reports an error.
{
	echo " ";
	echo"display each value as array ";
	echo $var;
}


...again more function definitions.
string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen = -1 ]]]] )


if he writes his code like this.....
$output = file_get_contents('path/to/file.txt'); //<--- Reads entire file into a string, so $output is a string and contains the files content.
$output = explode(",",$output); //<-- Split $output by "," and returns an array, $output is an array.

// these are moved outside of foreach loop so they do not repeat with each pass.
echo " ";
echo "display each value as array";

foreach($output as $fragment)
{
echo $fragment."<br>"; // this will print each "fragment" of the variable array $output.
// <br> is for browser output, change to \n for consol output.
}


----------------- BTW
if he wants to read each and every character then his original code will never work unless the contents of his source file contains a comma between each character.

If it is just text then he could just load the file contents using the file_get_contents() then use strlen to get the total character count of the contents and then he can use a for to walk through each character of the file contents. like this....

$output = file_get_contents('path/to/file.txt');
$cnt = strlen($output);
for$i=0;$i<$cnt;$i++)
{
echo $output[$i]."
";
}
RantRe: PHP File Open and Reading character by character Pin
Macotti20-Oct-10 15:45
Macotti20-Oct-10 15:45 
GeneralRe: PHP File Open and Reading character by character Pin
cjoki21-Oct-10 7:38
cjoki21-Oct-10 7:38 
AnswerRe: PHP File Open and Reading character by character Pin
Macotti20-Oct-10 1:07
Macotti20-Oct-10 1:07 
AnswerRe: PHP File Open and Reading character by character Pin
solarpowerlightssource22-Oct-10 12:21
solarpowerlightssource22-Oct-10 12:21 
QuestionLogin and registration system using php Pin
Shamol-nahid11-Oct-10 14:24
Shamol-nahid11-Oct-10 14:24 
AnswerRe: Login and registration system using php [modified] Pin
Karthik. A11-Oct-10 15:06
Karthik. A11-Oct-10 15:06 
QuestionLogin Pin
Shamol-nahid11-Oct-10 14:17
Shamol-nahid11-Oct-10 14:17 
AnswerRe: Login Pin
cjoki12-Oct-10 4:34
cjoki12-Oct-10 4:34 
QuestionRe: Login Pin
Macotti20-Oct-10 0:53
Macotti20-Oct-10 0:53 
QuestionAdding Perl Script to .NET web project Pin
iqbalshekh10-Oct-10 22:11
iqbalshekh10-Oct-10 22:11 
AnswerRe: Adding Perl Script to .NET web project Pin
jschell15-Oct-10 8:24
jschell15-Oct-10 8:24 
GeneralRe: Adding Perl Script to .NET web project Pin
iqbalshekh22-Oct-10 1:10
iqbalshekh22-Oct-10 1:10 
Questioni need guides on web upload images+text at the same time for my site Pin
hishamudin10-Oct-10 8:46
hishamudin10-Oct-10 8:46 
AnswerCross-post warning Pin
Peter_in_278010-Oct-10 13:42
professionalPeter_in_278010-Oct-10 13:42 
QuestionHow i can add template to php ? Pin
Honeyboy_209-Oct-10 0:09
Honeyboy_209-Oct-10 0:09 
AnswerRe: How i can add template to php ? Pin
Gerben Jongerius9-Oct-10 2:40
Gerben Jongerius9-Oct-10 2:40 
AnswerRe: How i can add template to php ? Pin
jafor iqbal17-Oct-10 20:31
jafor iqbal17-Oct-10 20:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.