Demonic Posted September 20, 2006 Share Posted September 20, 2006 [code]<?phpfunction therror($error){print "<b>Sorry an error occured:</b>".$error;return $error;}?>[/code]Can anyone tell me why when i try and use this function it wont allow white spaces? Link to comment https://forums.phpfreaks.com/topic/21351-function-wont-allow-white-spaces/ Share on other sites More sharing options...
btherl Posted September 20, 2006 Share Posted September 20, 2006 Can you tell us what you did, what you expected to happen and what actually happened? We need all those 3 things to tell you what's going wrong. Link to comment https://forums.phpfreaks.com/topic/21351-function-wont-allow-white-spaces/#findComment-95057 Share on other sites More sharing options...
wildteen88 Posted September 20, 2006 Share Posted September 20, 2006 By white spaces you mean line breaks/carriage returnsEg you have a string like this:[code]This stirnghas line breaksin it[/code]But when you go to echo the string it displays like this:[code]This stirnghas line breaksin it[/code]If that is whats happing its becuase the browser ignores whitespace chars. In order for the browser to parse whitespace characters you will need to force it, by either using the preformated text tag ([nobbc]<pre>text here</pre>[/nobbc]). Or you'll have to convert the new lines into a HTML line break ([nobbc]<br />[/nobbc]) using a PHP function called nl2br()You're best of going with the PHP version. SO uses this as the PHP code:[code=php:0]<?phpfunction therror($error){ print "<b>Sorry an error occured:</b>" . nl2br($error); return $error;}?>[/code] Link to comment https://forums.phpfreaks.com/topic/21351-function-wont-allow-white-spaces/#findComment-95170 Share on other sites More sharing options...
Demonic Posted September 20, 2006 Author Share Posted September 20, 2006 Neither of thesesWhen i went to use the script it wouldnt allow to to use white spacestherror(Hey);would work^ when i tryed below it wouldnt worktherror(Hey that is not allowed);O_O[quote]Parse error: parse error, unexpected T_STRING in C:\thephp\xampp\htdocs\support\functions\errortest.php on line 8[/quote]code:[code]<?phpfunction therror($error){ print "<b>Sorry an error occured:</b>" . nl2br($error); return $error;}therror(Hello person);?>[/code] Link to comment https://forums.phpfreaks.com/topic/21351-function-wont-allow-white-spaces/#findComment-95222 Share on other sites More sharing options...
ToonMariner Posted September 20, 2006 Share Posted September 20, 2006 It would not allow white space in $error? Is that what you are saying? The function call you have should pass the string as a string so put it in quotes like so...theerror('Hello Person'); Link to comment https://forums.phpfreaks.com/topic/21351-function-wont-allow-white-spaces/#findComment-95226 Share on other sites More sharing options...
Demonic Posted September 20, 2006 Author Share Posted September 20, 2006 Ah :) Thanks. ill see if that works. Link to comment https://forums.phpfreaks.com/topic/21351-function-wont-allow-white-spaces/#findComment-95503 Share on other sites More sharing options...
Demonic Posted September 20, 2006 Author Share Posted September 20, 2006 Thanks works perfectly now XD.closed Link to comment https://forums.phpfreaks.com/topic/21351-function-wont-allow-white-spaces/#findComment-95504 Share on other sites More sharing options...
Recommended Posts