bhv
bhv

Reputation: 5378

php, wordpress add line break with in two echo statements

<?php if (is_page_template()) { 
  echo get_page_template_slug(); 
  echo get_page_template() ;
?>

is there any way to print this two echo statements in different line with out closing php and use html to line break

in plane php

<?php if ( 1 ==1 ) {
  echo 'first line';
  echo 'second line';
}

the two echo values might not be string in all cases


how to add line break after an echo statement, so that the next statement prints in new line

Upvotes: 1

Views: 3462

Answers (7)

Shubham
Shubham

Reputation: 539

Here is my simple solution :

<?php
    echo "First line\n";
    echo "Second Line";

If you change double quotes with single quote it will not work. What you can do is :

<?php
    echo 'First Line' . "\n";
    echo 'Second line';

Upvotes: 0

preLa
preLa

Reputation: 11

Just use

echo "line1
"; echo "Line2";

Upvotes: 0

Deepa
Deepa

Reputation: 184

You can also use nl2br() php function which inserts line breaks where newlines (\n) occur in the string:

<?php
  echo nl2br("One line.\nAnother line.");
?>

Output :

One line.

Another line.

Upvotes: 0

Stender
Stender

Reputation: 2492

There is plenty of ways doing this - the way i like it when i have few php values is like this.

<?php if ( 1 ==1 ) : ?>
<!-- normal html here -->
  <div>
    <p class="whatever"><?php echo 'first line'; ?></p>
    <p class="whatever2"><?php echo 'second line'; ?></p>
  </div>
<?php endif; ?>

Upvotes: 0

Annapurna
Annapurna

Reputation: 549

<?php if (is_page_template()) { 
  echo get_page_template_slug() . '</br>'; 
  echo get_page_template();
?>

try this

Upvotes: 1

Zaid Bin Khalid
Zaid Bin Khalid

Reputation: 763

Try it like this. Use concatenation and use HTML </br> tag. Or you can use '\n' for line break.

<?php if ( 1 ==1 ) {
  echo 'first line'.'<br>'.'second line';
}

Upvotes: 1

danivdwerf
danivdwerf

Reputation: 274

You can just add html in the echo:

echo "my line <br />";
echo "second line";

Upvotes: 1

Related Questions