Jump to content

function wont allow white spaces


Demonic

Recommended Posts

By white spaces you mean line breaks/carriage returns

Eg you have a string like this:
[code]This stirng
has
line breaks
in 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]<?php
function therror($error)
{
    print "<b>Sorry an error occured:</b>" . nl2br($error);

    return $error;
}
?>[/code]
Link to comment
Share on other sites

Neither of theses

When i went to use the script it wouldnt allow to to use white spaces

therror(Hey);

would work^ when i tryed below it wouldnt work

therror(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]
<?php
function therror($error)
{
    print "<b>Sorry an error occured:</b>" . nl2br($error);

    return $error;
}
therror(Hello person);
?>
[/code]
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • 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.