Jump to content

Help with PHP adding white space to a string


DallasNYC

Recommended Posts

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
Link to comment
Share on other sites

[code]
$var = trim($var);
[/code]

[!--quoteo(post=352697:date=Mar 7 2006, 04:53 PM:name=DallasNYC)--][div class=\'quotetop\']QUOTE(DallasNYC @ Mar 7 2006, 04:53 PM) [snapback]352697[/snapback][/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]
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

[!--quoteo(post=352702:date=Mar 7 2006, 07:14 PM:name=DallasNYC)--][div class=\'quotetop\']QUOTE(DallasNYC @ Mar 7 2006, 07:14 PM) [snapback]352702[/snapback][/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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.