- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print newline in PHP in single quotesn
Since
can’t be used with single quotes, we need to resort to other options.
- When using command line interface, the constant PHP_EOL can be used.
- When using with browsers, the ‘<br>’ can be used.
Both the options have been demonstrated below.
<?php if (PHP_SAPI === 'cli') { return PHP_EOL; } else { return "<BR/>"; } ?>
Suppose our option was not cli, the ‘else’ part will be executed and a newline will be printed −
Example
<?php $var_1 = 'hi'; $var_2 = "
"; $var_3 = 'hello'; echo $var_1 . $var_2 . $var_3; echo PHP_EOL; $var_2 = str_replace("
", '
', $var_2); echo $var_1 . $var_2 . $var_3; echo PHP_EOL; ?>
Output
This will produce the following output −
hi hello hi
hello
- Related Articles
- Print newline in PHP in single quotes\n
- Single quotes vs. double quotes in C or C++\n
- Is there a PHP function that only adds slashes to double quotes NOT single quotes
- How to print without newline in Python?
- Single and Double Quotes in Perl
- How to escape single quotes in MySQL?
- Escaping/encoding single quotes in JSON encoded HTML5 data attributes
- Using MySQL keywords in a query surrounded with single quotes?
- How to insert date in single quotes with MySQL date formats?
- What is the difference between single and double quotes in python?
- What is the difference between single and double quotes in JavaScript?
- How to print double quotes with the string variable in Python?
- What do single quotes do in C++ when used on multiple characters?
- Using single quotes around database and table name isn’t working in MySQL?
- print() function in PHP
- Why does the update command in MySQL insist on using slanted single quotes?

Advertisements