Jump to content

new to php


coder13

Recommended Posts

I am trying to do a simple return between two strings in a php block.  All i get is a blank page when i insert the echo /n

line.... what am i doing wrong?

 

this is my code:

 

<?php

$str = "my string";

$str1 = "my other string";

echo $str;

echo /n;

echo $str1;

?>

Link to comment
Share on other sites

thanks for the reply but it is still not working.

 

<?php

$str = "my string";

$str1 = "my other string";

echo $str;

echo "\n";

echo $str1;

?>

 

this returns: 

my string my other string

 

i want it to return:

my string

my other string

 

 

Link to comment
Share on other sites

The newline character is working in regard to your generated output (look at your source code in the browser).  The 'problem' is that you're looking at it with the browser.  To a browser, an HTML line break element (<br>) is what will make a new line visible on the screen.

 

In other words, your generated code is:

 

my string
my other string

 

But since browsers ignore white space, it's being displayed as:

 

my stringmy other string

 

To make it look right in the browser, swap \n for <br>

Link to comment
Share on other sites

The "\n" is not the newline on the browser display. To the browser, that character is another whitespace character. To get a newline on the browser, you need to use the HTML tag "<br>". If you had looked at the source, you would have seen the newline between those strings:

<?php
$str = "my string";
$str1 = "my other string";
echo $str;
echo "<br>";
echo $str1;
?>

or

<?php
$str = "my string";
$str1 = "my other string";
echo "$str<br>$str1";
?>[code]

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.