Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Differentiating between nulls & blanks in array 1

Status
Not open for further replies.

CliveC

Programmer
Nov 21, 2001
1,222
US
In testing the array values in TEST1.PHP, I want to differentiate between blank lines and nulls. Any ideas?
I have tried testing for " ", "\n", " \r\n" etc

Code:
TEST1.HTM
<html><body>
<form name="mail" method="post" enctype="multipart/form-data"
 action="[URL unfurl="true"]http://chemtechs.com/kiss/test1.php">[/URL]
Message:<br /> 
<textarea name="t" rows="6" cols="36">
line-1
line-2

line-4
</textarea><br />
<input value="Send" type="submit" />
</form></body></html>

Code:
TEST1.PHP
<?php
$text=$_POST['t'];
$line = explode("\n", $text);
for ($i=0; $i<9; $i++) {
 echo ($line[$i]);
 if ($line[$i]=="") {echo('null-line');}
 if ($line[$i]=="\r\n") {echo('blank-line');}
 echo ('<br />');
}
?>

Clive
 
If you're exploding, then the newlines go away. Think about it and you'll see that any line "" had to have a \n before and after it (unless it was the first or last line) so was a blank line.
 
You haven't really proven that it doesn't exist, you're only checking for a couple of possibilities and have no "else". Try doing something like:
Code:
echo "|" . $line[$i] . "|\n";
to see if anything is there. If there is, you'll have figure out what non visible character is there, possibly by printing the ascii value if anything in it.

Showing the output would be helpful.
 
Tried that and it appears to be a space but space does not work.

Code:
|line-1 | 
|line-2 | 
| | 
|line-4 | 
|| null-line
|| null-line
|| null-line
|| null-line
|| null-line

Code:
<?php
$text=$_POST['t'];
$line = explode("\n", $text);
for ($i=0; $i<9; $i++) {
 echo "|" . $line[$i] . "|\n";
// echo ($line[$i]);
 if ($line[$i]=="") {echo('null-line');}
 if ($line[$i]==" ") {echo('blank-line');}
 echo ('<br />');
}
?>


Clive
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top