PHP Lacks Quoting Power

Why doesn’t PHP have a quoting function similar to qq() in Perl? PHP is a web scripting language used to build dynamic HTML and output it to a browser. Why shouldn’t it be easy to output HTML strings that contain double quotes?

Firstly, I don’t want to escape every double quote (\”) which results in:

$html .= "<table border=\"$color\" background=\"ccccff\">\n";

Secondly, I don’t want to use PHP’s heredoc syntax (<<<): [php]$html = <<< ENDHTML &lt;table border="$color" background="ccccff"&gt; ENDHTML;[/php] This is overkill for single lines of HTML. I want to do something like this in PHP: [php]$html = qq | &lt;table border="$color" background="ccccff"&gt; |;[/php] Any ideas?

4 thoughts on “PHP Lacks Quoting Power

  • July 29, 2005 at 10:23 pm
    Permalink

    I don’t think htmlspecialchars is what he is looking for here. He is not trying to get the browser to render double quotes properly, he is trying to include double quotes in a string without having to escape them.
    I don’t really know of a better way to do this. Please post if you find one.

  • July 31, 2005 at 2:26 am
    Permalink

    That is exactly what I am looking for Bryce.

  • July 31, 2005 at 3:57 am
    Permalink

    Ahhh.. in that case, you’re screwed. :) I just use single quotes when possible, and backslash it when I do need a double quote.

Comments are closed.