استفاده از Heredocs و Nowdocs
Heredocs و Nowdocs دو روش برای تعریف رشته های بزرگ در PHP می باشند. نحوه تعریف رشته در این دو روش به صورت زیر است :
<?php $string = <<<HEREDOC ... HEREDOC; ?>
<?php $string = <<<'NOWDOC' ... NOWDOC; ?>
تفاوت این دو در این است که در HEREDOC متغیر ها همانند دابل کوتیشن پردازش می شوند ولی در NOWDOC نه. به مثال های زیر توجه کنید :
HEREDOC
<?php $heredoc = 'HEREDOC'; $string = <<<HEREDOC "The $heredoc syntax is much cleaner to me and it is really useful ." HEREDOC; echo $string; ?>
The HEREDOC syntax is much cleaner to me and it is really useful .
NOWDOC
<?php $nowdoc= 'NOWDOC'; $string = <<<'NOWDOC' "The $nowdoc syntax is much cleaner to me and it is really useful ." NOWDOC; echo $string; ?>
The $nowdoc syntax is much cleaner to me and it is really useful .
به این نکات هم توجه کنید که :