Does anyone see anything wrong with the script below? It works but I'm wondering if there is a problem with the theory.
If I set the "2" in the strlen() function to "1" like so:
if ( strlen($GetLine["1"]) > "1")
then the $CurrentDescription is filled with the "plus text bla bla" text (for lines three and five). It shouldn't be doing that I don't think.
In other words, if the second component of the line, which is the picture description, is empty then the "if (strlen($GetLine[1] ...." function should be false and the $CurrentDescription variable should not be filled when the number to the right of the ">" operator is set at "1".
The script works ok if I leave the number to the right of the ">" operator set at "2". But it kind of bugs me when I'm wondering if it might get crossed up somehow later down the road.
// Script up here writes the lines to the WriteTo.txt file.
// Text stored in WriteTo.txt file - stored in a different folder.
Picture1.jpg [TAB] Picture One description
Picture2.jpg [TAB] Picture Two description
Picture3.jpg [TAB] {$GetLine[1] is empty - no description}
Picture4.jpg [TAB] Picture Four description
Picture5.jpg [TAB] {$GetLine[1] is empty - no description}
// Script to extract data from text file.
// $GetLine[0] is the picture name. $GetLine[1] is the picture description.
// If the picture has no description in the text file $GetLine[1] is empty.
$TheFile = $DirectoryPathName."/WriteTo.txt";
$Open = fopen ($TheFile, "r");
if ($Open) {
$Data = file ($TheFile);
for ($n = 0; $n < count($Data); $n++) {
$GetLine = explode("\t", $Data[$n]);
// If I sent the "2" to a "1" the snippet returns true
// and fills the $CurrentDescription variable. It shouldn't be doing that.
// If $GetLine["1"] is empty then it would not be greater than one so it
// should return false and not fill $CurrentDescription if the right is set at "1".
if ( strlen($GetLine["1"]) > "2") {
$CurrentDescription = "$GetLine[1] plus text bla bla";
}
$Pictures[] = "bla bla bla $GetLine[0] more bla bla $CurrentDescription. bla bla";
}
}
Thanks.