Heredoc is a way to create string in PHP with more lines but without using quotations. Here's an example
<?php
function some_function(){
$content = '<a onClick="test(\'somevalue\')">Test</a>';
return $content;
}
?>
can be written
<?php
function some_function(){
$content = <<<EOF
<a onClick="test('somevalue')">Test</a>
EOF;
return $content;
}
?>
Notice that using the heredoc we don't have to escape the quote('), that also apply to double quotes(").
The following example also does the same thing.
<?php
function some_function(){
return <<<EOF
<a onClick="test('somevalue')">Test</a>
EOF;
}
?>
The EOF itself can be replace by any string you want. Using a string like YHRGT is a good idea to make sure that string won't appear in your content.
0 comments:
Post a Comment