Jump to content

Archived

This topic is now archived and is closed to further replies.

Demonic

function wont allow white spaces

Recommended Posts

[code]
<?php
function 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?

Share this post


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

Share this post


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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
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');

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×

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.