Dergam Posted July 11, 2012 Share Posted July 11, 2012 special characters don't work (\n, \t, ...) what is the problem <?php $string = "Hello \nWorld"; echo $string; ?> Output: Hello World Not: Hello World Link to comment https://forums.phpfreaks.com/topic/265520-special-characters-dont-work-n-t/ Share on other sites More sharing options...
KevinM1 Posted July 11, 2012 Share Posted July 11, 2012 It doesn't work because you're looking at it with a browser, which anticipates HTML. \n is meaningless to a browser (at least, in terms of what it renders to the screen). Your normal white space characters won't work. Instead, use <br />, the HTML tag for a line break. Link to comment https://forums.phpfreaks.com/topic/265520-special-characters-dont-work-n-t/#findComment-1360793 Share on other sites More sharing options...
Barand Posted July 11, 2012 Share Posted July 11, 2012 Alternatively, wrap the output inside <pre>...</pre> tags. Then tabs and newlines will be output as expected. Link to comment https://forums.phpfreaks.com/topic/265520-special-characters-dont-work-n-t/#findComment-1360795 Share on other sites More sharing options...
ManiacDan Posted July 11, 2012 Share Posted July 11, 2012 Note that your thread title fell into the classic trap of new programmers. You said "special characters don't work." That's not the problem. The problem is "I don't see special characters when I expect to see them." The problem is that you're viewing your output incorrectly (in a browser, rather than plain text), not anything to do with PHP. Make sure you define the question properly, it may help you understand a way to fix it on your own. Link to comment https://forums.phpfreaks.com/topic/265520-special-characters-dont-work-n-t/#findComment-1360801 Share on other sites More sharing options...
Dergam Posted July 12, 2012 Author Share Posted July 12, 2012 KevinM1& Barand thank you. I understand the cause of the problem now. ManiacDan you are right. I am not a native English speaker, so expect faults like this and I am sorry, it wasn't intended. Link to comment https://forums.phpfreaks.com/topic/265520-special-characters-dont-work-n-t/#findComment-1361110 Share on other sites More sharing options...
ManiacDan Posted July 12, 2012 Share Posted July 12, 2012 Dergam, I wasn't attempting to scold you. The phrasing lead me to assume something about the way you were thinking about the problem. If you were thinking incorrectly, it would be good for you to think a different way so you could easily solve the problems. Good that you got it working, and keep at it! you're welcome here. Link to comment https://forums.phpfreaks.com/topic/265520-special-characters-dont-work-n-t/#findComment-1361129 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.