1
<?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

bhv
  • 5,188
  • 3
  • 35
  • 44
  • 1
    Add ``echo '
    ';`` or ``echo '\n\n';`` in between the two lines?
    – user1438038 Aug 02 '17 at 10:31
  • the two echo values might `not be string` in all cases – bhv Aug 03 '17 at 03:22
  • So what? You can concatenate them anyway. The arguments of [``echo()``](http://php.net/manual/en/function.echo.php) are always ``string``. – user1438038 Aug 03 '17 at 06:58
  • thats already added in question, but some users did't notice that , any how please delete comments which are not related to question , i too will do that – bhv Aug 03 '17 at 08:53

7 Answers7

1

You can just add html in the echo:

echo "my line <br />";
echo "second line";
danivdwerf
  • 234
  • 2
  • 16
1

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';
}
Zaid Bin Khalid
  • 748
  • 8
  • 25
1
<?php if (is_page_template()) { 
  echo get_page_template_slug() . '</br>'; 
  echo get_page_template();
?>

try this

Annapurna
  • 529
  • 1
  • 6
  • 19
0

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; ?>
Stender
  • 2,446
  • 1
  • 14
  • 22
0

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.

Deepa
  • 184
  • 1
  • 2
  • 16
0

Just use

echo "line1
"; echo "Line2";

preLa
  • 11
  • 3
0

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';
Shubham
  • 497
  • 10
  • 23