How to skip a line in php?

i have this in php :

 echo '"dayCaption":"'.$colNumberOfWeek.' '.$numberOfWeek.'",'; 

But i want to complete this . I want to skip a line and add another variable ( $xxx for exemple ) in parentheses...

Thanks

asked Feb 23, 2017 at 8:56

9

You may try this

   echo '"dayCaption":"'.$colNumberOfWeek.' '.$numberOfWeek.'", '; 
  echo "</br> ";
  echo "(";
  echo $xxxx;
  echo ")";

answered Feb 23, 2017 at 9:02

How to skip a line in php?

6

i think u want to put in a Enter. so after your last value on line 1 put in +"/r/n" (not sure if it has to be in quotes)

 echo $value1 . $value2 . "/r/n" . $value3

 echo '"dayCaption":"'.$colNumberOfWeek.' '.$numberOfWeek.' './r/n.' '.$value3.'",'; 

answered Feb 23, 2017 at 9:01

How to skip a line in php?

B. DionysB. Dionys

8847 silver badges33 bronze badges

7

I have updated your code, please try this code:

echo "dayCaption: ".$colNumberOfWeek." ".$numberOfWeek."<br/>(".$xxx.")";

Or

echo "dayCaption: ".$colNumberOfWeek." ".$numberOfWeek;
echo "<br/>";
echo "(".$xxx.")";

Both will display the same results.

I hope, this will be helpful to you.

answered Feb 23, 2017 at 9:08

How to skip a line in php?

Prateek VermaPrateek Verma

8591 gold badge6 silver badges9 bronze badges

❮ PHP String Reference

Example

Insert line breaks where newlines (\n) occur in the string:

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

The browser output of the code above will be:

One line.
Another line.

The HTML output of the code above will be (View Source):

One line.<br />
Another line.

Try it Yourself »


Definition and Usage

The nl2br() function inserts HTML line breaks (<br> or <br />) in front of each newline (\n) in a string.


Syntax

Parameter Values

ParameterDescription
string Required. Specifies the string to check
xhtml  Optional. A boolean value that indicates whether or not to use XHTML compatible line breaks:
  • TRUE- Default. Inserts <br />
  • FALSE - Inserts <br>


Technical Details

Return Value:Returns the converted string
PHP Version:4+
Changelog:The xhtml parameter was added in PHP 5.3.
Before PHP 4.0.5, it inserted <br>. After PHP 4.0.5 it inserts <br />.

More Examples

Example

Insert line breaks where newlines (\n) occur, using the xhtml parameter:

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

The browser output of the code above will be:

One line.
Another line.

The HTML output of the code above will be (View Source):

One line.<br>
Another line.

Try it Yourself »


❮ PHP String Reference


🏠 » Q&A » How To Echo A Line Break / New Line In PHP

Answer: In PHP to echo a new line or line break use ‘\r\n’ or ‘\n’ or PHP_EOL

If HTML uses <br/> to create a line break, in PHP you can create a new line using 3 different methods :

1. PHP new line character ‘\n’ or ‘\r\n’

‘\n’ or ‘\r\n’ is the easiest way to embed newlines in a PHP string. Also, ‘\n’ can be used to create line breaks when creating PHP text files.

See the following example:

echo"Seegatesite.com\r\nThe best programming blog";

Result :

How to skip a line in php?

What is the difference  ‘\n’ or ‘\r\n’ ?

\n Used to write a new line on a UNIX system, while Windows reads a new line with the \r\n character.

2.PHP_EOL: PHP Core Predefined Constants

PHP_EOL is predefined constants to translate the end of a line in PHP. Source : PHP Manual

Example:

echo"Create Line Break PHP".PHP_EOL."With PHP_EOL";

Result :

How to skip a line in php?

3. Using nl2br() 

Used to add HTML line breaks in a string (the HTML code we usually use to create new lines <br/>)

Example :

echo nl2br("Seegatesite.com \nsharing and learning programming");

Result :

How to skip a line in php?

Conclusion :

The three methods above used according to your needs in creating new lines in PHP.

This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Reader Interactions

How do I ignore a line in PHP?

For a single line of PHP, you can just do this: // echo $phone; And that single line will be commented out. If what you're commenting spans more than one line, use the /* commented code */ method.

What is the use of \r in PHP?

\r is a Carriage Return \n is a Line Feed (or new line). On Windows systems these together make a newline (i.e. every time you press the enter button your fix will get a \r\n ). In PHP if you open a Windows style text file you will get \r\n at the end of paragraphs / lines were you've hit enter.

How do I go back a line in PHP?

Answer: In PHP to echo a new line or line break use '\r\n' or '\n' or PHP_EOL.

What is new line character in PHP?

It is a character in a string which represents a line break, which means that after this character, a new line will start. There are two basic new line characters: LF (character : \n, Unicode : U+000A, ASCII : 10, hex : 0x0a): This is simply the '\n' character which we all know from our early programming days.

Tải thêm tài liệu liên quan đến bài viết How to skip a line in php?