Jump to content


Photo

Help with PHP adding white space to a string


  • Please log in to reply
3 replies to this topic

#1 DallasNYC

DallasNYC
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 08 March 2006 - 12:53 AM

Hi, I spend alot of my time over at flashkit.com dealing mostly with flash. But I was recently involved with a thread dealing with PHP adding unwanted white space to a string. It turns out that if an extra line is left after the PHP closing tag, a space could get added to the string...

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
In php, if you are using an editor that has line numbers you may have something like this:

66 echo 'response=passed';
67 ?>
68


You would need to remove line 68. PHP sees that as output. Your script should end as this:

66 echo 'response=passed';
67 ?>

And no extra line.

I can replicate this issue and solve this issue just by changine the above code around.[/quote]
[a href=\"http://flashkit.com/board/showthread.php?t=675912\" target=\"_blank\"]http://flashkit.com/board/showthread.php?t=675912[/a]

Ive only done a little PHP coding, but this interest me because I never read anything about this.

I'm curious if someone can enlighten me more about this issue? Is there more documentation/articles about what other things could result in whitespace being added to a string? (I did a search for 'white space' etc, but came up with too many results)

Recently there is a new thread with another person having problems with added whitespace to thier strings..
[a href=\"http://flashkit.com/board/showthread.php?t=676326&page=2&pp=20\" target=\"_blank\"]http://flashkit.com/board/showthread.php?t...26&page=2&pp=20[/a]
I notice that in this particular issue, the author follows the echo tag with a "//" remark tag, but was not certain if that would cause the same white space issue?

Thanks so much,
Dallas

#2 solarisuser

solarisuser
  • Members
  • PipPipPip
  • Advanced Member
  • 122 posts

Posted 08 March 2006 - 01:10 AM

$var = trim($var);

[!--quoteo(post=352697:date=Mar 7 2006, 04:53 PM:name=DallasNYC)--][div class=\'quotetop\']QUOTE(DallasNYC @ Mar 7 2006, 04:53 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hi, I spend alot of my time over at flashkit.com dealing mostly with flash. But I was recently involved with a thread dealing with PHP adding unwanted white space to a string. It turns out that if an extra line is left after the PHP closing tag, a space could get added to the string...
[a href=\"http://flashkit.com/board/showthread.php?t=675912\" target=\"_blank\"]http://flashkit.com/board/showthread.php?t=675912[/a]

Ive only done a little PHP coding, but this interest me because I never read anything about this.

I'm curious if someone can enlighten me more about this issue? Is there more documentation/articles about what other things could result in whitespace being added to a string? (I did a search for 'white space' etc, but came up with too many results)

Recently there is a new thread with another person having problems with added whitespace to thier strings..
[a href=\"http://flashkit.com/board/showthread.php?t=676326&page=2&pp=20\" target=\"_blank\"]http://flashkit.com/board/showthread.php?t...26&page=2&pp=20[/a]
I notice that in this particular issue, the author follows the echo tag with a "//" remark tag, but was not certain if that would cause the same white space issue?

Thanks so much,
Dallas
[/quote]


#3 DallasNYC

DallasNYC
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 08 March 2006 - 01:14 AM

Thanks solaris, I am aware of trim() and other ways to remove the whitespace. I'm trying to learn ways to prevent it from happening in the first place.

I'm curious if someone can enlighten me more about this issue? Is there more documentation/articles about what other things could result in whitespace being added to a string?

#4 greycap

greycap
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 08 March 2006 - 02:57 AM

[!--quoteo(post=352702:date=Mar 7 2006, 07:14 PM:name=DallasNYC)--][div class=\'quotetop\']QUOTE(DallasNYC @ Mar 7 2006, 07:14 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Thanks solaris, I am aware of trim() and other ways to remove the whitespace. I'm trying to learn ways to prevent it from happening in the first place.

I'm curious if someone can enlighten me more about this issue? Is there more documentation/articles about what other things could result in whitespace being added to a string?
[/quote]

From what I can tell, you are loading a .php file into a flash animation.

Within the <? ?> tags, thats all interpreted by PHP. Everything else is interpreted as html. That extra line is output by your webserver, not by php.

This isnt a bug, just an apparent misunderstanding.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users