PHP heredoc Syntax – Alternative to Assigning String Variables

by Carey on November 24, 2010

Post image for PHP heredoc Syntax – Alternative to Assigning String Variables

Working with large strings of text in your php application can often look messy and clumsy. An alternative method is to use the heredoc syntax:

{code type=php}$longString = <<

{ 1 comment… read it below or add one }

Charlie F. September 4, 2009 at 1:27 pm

The code in the example doesn’t work for me. Try this instead. 🙂

$longString = <<<EOT
Here’s a better version that works!
EOT;

Reply

Leave a Comment

Previous post:

Next post: