|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-10-17 07:48 UTC] work at web-sav dot de
Description:
------------
How to merge together HTML/JS/SQL and PHP inside non-view scripts:
// looks messy
$htmlSingle = '<a href="' . {$url} . '">' . {$label} . '</a>';
// good, but needs to be escaped
$htmlDouble = "<a href=\"{$url}\">{$label}</a>;
// breaks code clearity (especially inside classes)
$htmlHeredoc = <<<HTML
<a href="{$url}">{$label}</a>
HTML;
None of the above solutions are really perfect for solving one of the most common task in PHP. So a mixture of the heredoc syntax (code injection for phpstorm) and the double quotes (one liners) would be perfect imo. Maybe something like this:
// without code injection feature
$html = :|<a href="{url}">{$label}</a>|;
// with code injection
$html = :HTML|<a href="{url}">{$label}</a>|;
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 04:00:02 2025 UTC |
FWIW, you can also do $html = sprintf('<a href="%s">%s</a>', $url, $label);