Bike Posted February 4, 2021 Share Posted February 4, 2021 Hello everyone, I encountered a strange behavior when I do something like this (which I actually do all the time): <p><? print $page->something; ?></p> What happens is that there is a whitespace at the end which is selectable at least in FF and visible in most other browsers when selected. You can find it on the PW website as well, e.g. headline on this page ("About ProcessWire "): https://processwire.com/about/It must have something to do with PW because I cannot find that bug anywhere else. I thought it might have something to do with how the code is formatted but it proved wrong. The whitespace is of course not in the variables itself since it even happens with print "hello"; It's not a big thing but it annoys me anyway... Bike Link to comment Share on other sites More sharing options...
adrian Posted February 4, 2021 Share Posted February 4, 2021 What type of field is "something"? I am not seeing any whitespace issue here with a text field. Also, that code as you have it is a bit weird and might not actually work at all on some systems. You either want the opening php tag to be: <?php or, you want to use like this: <p><?=$page->something?></p> Link to comment Share on other sites More sharing options...
Bike Posted February 4, 2021 Author Share Posted February 4, 2021 Hi @adrian, fieldtype can be anything, doesn't depend on it. As I said it even occurs with a string. Never had any issues with that code since short tag is enables. Using print instead of echo is just a schitck! Link to comment Share on other sites More sharing options...
adrian Posted February 4, 2021 Share Posted February 4, 2021 In PHP 8.0 the deprecation notice is converted into a parse error: If short_open_tag is enabled, the use of <? is a parse error. If short_open_tag is disabled, <? has no special meaning (as before). In PHP 9.0 support for short_open_tag is dropped entirely: <? never has special meaning, it is always interpreted as plain text. This deprecation and removal plan avoids unintentional code leaks during PHP version upgrades. https://wiki.php.net/rfc/deprecate_php_short_tags_v2 As for echo vs print - I am not suggesting one over the other - just that you shouldn't use either in a <? shorttag because it won't be available soon. <?= is still OK though. As for the whitespace, here is a test I just tried: Now, I do see a whitespace character after the "11111" but that is after the </p> I don't see any whitespace where it shouldn't be. Perhaps you can do a similar test with screenshots to show us what you are seeing. 2 Link to comment Share on other sites More sharing options...
BillH Posted February 4, 2021 Share Posted February 4, 2021 Are the tags in your HTML on separate lines? If so, Firefox will insert a space. <p> Firefox will add a space at the end of this. </p> <p>But not at the end of this.</p> I haven't noticed this happening in other browsers, though perhaps I've missed something. I have a memory that Firefox has done this for many years at least, but I'm not sure. Note that the Inspect tool in Firefox Web Developer Tools re-formats the HTML for easy reading, repositioning tags for many elements, and it removes spaces before tags in at least some cases (which is not helpful and a bit strange in my opinion!), so it's not good for debugging such things. The Page Source tool is more useful. I note that the heading "About ProcessWire" does actually have a space at the end in the HTML source. This could be for various reasons - such as a Text Formatter, or simply somebody typing a space! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now