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');
?> 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');
?>
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');
?>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: bigoxygen |
last post by:
Is it possible to invoke a function from inside heredoc?
Thanks
|
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...
|
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:
...
|
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...
|
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...
|
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
|
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...
|
by: Jeff |
last post by:
I have this:
$content = <<<TD
$D
TD;
that fails silently and stops php even though errors are turned on
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| |