Ok guys.
I know its been a while.
but i still need some help with this.
This whole $startOfLine variable issue is still causing me confusion.
Everything in the script makes sense apart from the variable $startOfline.
Ok. I'll explain how i understand things and you can tell me where im going wrong or what im missing.
When i read the book (which there is a reference to at the top of this thread), it explains how $startOfLine has an initial value of '0' zero.
From here the script does its thing in order to justify the current line its working on. then at the bottom of the script we have:
$startOfLine += $originalLineLength + 1;
In the book it explains about the above line of code by telling us the following:
"the $startOfLine pointer is moved to the
start of the next line (adding 1 to the index to skip over the newline character)"
I don't understand how this can be at the start of the next line when $startOfLine will no longer be equal to '0' zero????????
I don''t understand what this will mean for the 2nd and 3rd (etc) iterations as the code progresses through the lines.
so we've now reached the 2nd iteration,, and this is where things confuse the hell out of me.
at the start of the 2nd iteration we come to these 2 lines of code which are causing me most of the confusion:
$originalLineLength = strpos( $myText, “\n”, $startOfLine ) - $startOfLine;
$justifiedLine = substr( $myText, $startOfLine, $originalLineLength );
..... so at the 2nd iteration, how is the $startOfLine still considered to be 'at the start of the line'?
because it is no longer going to be equal to '0' is it???
let me guess what the below code does. and just tell me if im correct.
in the below piece of code it uses the 'string position function'. i have learned about this function and its parameters. Maybe the book missed something important out,, but to me it looks like its taking the '$myText' variable as the text its going to work on and its searching for \n starting from the numerical value position of $startOfLine.
now i need to know,,, is the deduction of - $startOfLine; at the end of the below line, the first thing to happen, before strpos( $myText, “\n”, $startOfLine ) happens ???? or is it the other way around???
$originalLineLength = strpos( $myText, “\n”, $startOfLine ) - $startOfLine;
...... and the piece of code below. I need to ask about this. Is the $startOfLine variable now equal to the deducted sum above? or is it still set to the number it was set to after the first iteration???
$justifiedLine = substr( $myText, $startOfLine, $originalLineLength );