Re: count newlines in heredoc variable



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...@xxxxxxxxx> wrote:
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');
?>

.



Relevant Pages

  • Re: count newlines in heredoc variable
    ... but you just need double quotes: ... In a single-quoted string, the only interpreted escape sequences are \ ... John Peters ...
    (comp.lang.php)
  • Re: Pattern Matching Problem
    ... On Jul 5, 2007, at 8:50 PM, Ari Brown wrote: ... the word i am trying to match is "hello", WITH double quotes around it. ... Others have pointed out a problem with your case statement, but I think there's another problem here -- your #substitution isn't going to work in single-quoted string. ...
    (comp.lang.ruby)