473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

count newlines in heredoc variable

How could I count the number of newlines in a heredoc variable? This
outputs 0, but I thought heredoc preserved newlines?

<?
$test = <<<END
<a href="test5.php">adam</a>
<p>
Hi There
</p>
END;

echo substr_count($test, '\n');
?>
Jul 30 '08 #1
2 1636
Hi,

You're correct, but you just need double quotes: "\n".

In a single-quoted string, the only interpreted escape sequences are \
\ and \'.

Regards,

John Peters

On Jul 30, 2:21 pm, Adam Cantrell <cantrel...@gmail.comwrote:
How could I count the number of newlines in a heredoc variable? This
outputs 0, but I thought heredoc preserved newlines?

<?
$test = <<<END
<a href="test5.php">adam</a>
<p>
Hi There
</p>
END;

echo substr_count($test, '\n');
?>
Jul 30 '08 #2

Thank you very much -

Adam Cantrell

On Jul 30, 11:48*am, petersprc <peters...@gmail.comwrote:
Hi,

You're correct, but you just need double quotes: "\n".

In a single-quoted string, the only interpreted escape sequences are \
\ and \'.

Regards,

John Peters

On Jul 30, 2:21 pm, Adam Cantrell <cantrel...@gmail.comwrote:
How could I count the number of newlines in a heredoc variable? This
outputs 0, but I thought heredoc preserved newlines?
<?
$test = <<<END
* * *<a href="test5.php">adam</a>
* * *<p>
* * * * * Hi There
* * *</p>
END;
echo substr_count($test, '\n');
?>

Jul 30 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: bigoxygen | last post by:
Is it possible to invoke a function from inside heredoc? Thanks
7
by: flupke | last post by:
Hi, i have php script where i use a heredoc type of variabele to print out some html. In the heredoc, i use the values of several other vars. php snippet: $div=<<<END_DIV <DIV...
22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
6
by: bill | last post by:
Thanks to those that taught me to use heredoc to embed html in php. I don't want to start the html in php vs php in html discussion again., heredoc works a treat for that which I am doing...
5
by: lister | last post by:
Hi, I am trying to output a newline, but this doesn't work: echo "Line1\nLine2"; Before anyone says, I know HTML doesn't recognise newlines. I don't need newlines in the rendered HTML, I...
4
by: -Lost | last post by:
For example: var newlines = 'a\n\nb\n\nc'; alert(newlines); Yet, if I get that *exact* same line from an XMLHttpRequest's responseText, it is always alerted as: a\n\nb\n\nc
2
by: Matt F | last post by:
I can't seem to get heredoc to populate correctly with variables through a form. <textarea name="Template" rows="10" cols="80">Template Here</textarea> Contents could be something like: I want...
7
by: Jeff | last post by:
I have this: $content = <<<TD $D TD; that fails silently and stops php even though errors are turned on
2
by: someusernamehere | last post by:
hi, I have some heredoc on this way: $foo = <<<bar <form action="index.php" method="POST" name="user"> ............................................................................. HTML code...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.