How to store HTML code (with " ", ' ') inside a variable in php script?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Maxim Vexler

    #1

    How to store HTML code (with " ", ' ') inside a variable in php script?

    Hello to everyone,

    Assuming i have this simple script :

    <?PHP

    //Opening tag ='
    $html_header='
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    '; // Closing tag ='

    echo $html_header;

    ?>

    If the opening & closing tags are both ' then it works fine, but if the
    html script itself contains a ' then i need some way to escape it, no ?

    How should i do it if i had something like <HEAD><TITLE='P HP foo'></HEAD>?
  • Alvaro G Vicario

    #2
    Re: How to store HTML code (with &quot; &quot;, ' ') inside a variable in php script ?

    *** Maxim Vexler wrote/escribió (Thu, 11 Nov 2004 11:35:46 +0200):[color=blue]
    > If the opening & closing tags are both ' then it works fine, but if the
    > html script itself contains a ' then i need some way to escape it, no ?[/color]

    \'





    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- Thank you for not e-mailing me your questions
    --

    Comment

    • Maxim Vexler

      #3
      Re: How to store HTML code (with &quot; &quot;, ' ') inside a variable in phpscript ?

      Alvaro G Vicario wrote:[color=blue]
      > *** Maxim Vexler wrote/escribió (Thu, 11 Nov 2004 11:35:46 +0200):
      >[color=green]
      >>If the opening & closing tags are both ' then it works fine, but if the
      >>html script itself contains a ' then i need some way to escape it, no ?[/color]
      >
      >
      > \'
      >
      > http://es.php.net/manual/en/language.types.string.php
      >
      >
      >[/color]

      Note to self : Speak less, Read MORE (manuals).

      Thank you. :)

      Comment

      • Robin Goodall

        #4
        Re: How to store HTML code (with &quot; &quot;, ' ') inside a variable in phpscript ?

        Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:[color=blue]
        > How should i do it if i had something like <HEAD><TITLE='P HP foo'></HEAD>?[/color]

        [nit-picking]
        Tags and attributes should be lower case
        Attribute values should be in double quotes no single.
        <title=...> is not valid html; <title>PHP foo</title> is
        [/nit-picking]

        Comment

        • Matthias Esken

          #5
          Re: How to store HTML code (with &quot; &quot;, ' ') inside a variable in php script ?

          Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:
          [color=blue]
          > If the opening & closing tags are both ' then it works fine, but if the
          > html script itself contains a ' then i need some way to escape it, no ?[/color]

          Use \'

          Matthias

          Comment

          • Nikolai Chuvakhin

            #6
            Re: How to store HTML code (with &quot; &quot;, ' ') inside a variable in php script ?

            "Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il>"
            wrote in message news:<41934c85$ 1@news.012.net. il>...[color=blue]
            >
            > Assuming i have this simple script :
            >
            > <?PHP
            >
            > //Opening tag ='
            > $html_header='
            > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
            > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
            > '; // Closing tag ='
            >
            > echo $html_header;
            >
            > ?>
            >
            > If the opening & closing tags are both ' then it works fine, but if the
            > html script itself contains a ' then i need some way to escape it, no ?[/color]

            Yes. You should escape it with \ or just use the very versatile
            heredoc syntax.
            [color=blue]
            > How should i do it if i had something like <HEAD><TITLE='P HP foo'></HEAD>?[/color]

            Option One:

            $head = '<HEAD><TITLE=\ 'PHP foo\'></HEAD>';

            Option Two:

            $head = "<HEAD><TITLE=' PHP foo'></HEAD>";

            Option Three:

            $head = <<<ENDOFHEAD
            <HEAD><TITLE='P HP foo'></HEAD>
            ENDOFHEAD;

            Cheers,
            NC

            Comment

            • Chris Hope

              #7
              Re: How to store HTML code (with &quot; &quot;, ' ') inside a variable in php script ?

              Nikolai Chuvakhin wrote:
              [color=blue]
              > "Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il>"
              > wrote in message news:<41934c85$ 1@news.012.net. il>...[color=green]
              >>
              >> Assuming i have this simple script :
              >>
              >> <?PHP
              >>
              >> //Opening tag ='
              >> $html_header='
              >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
              >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
              >> '; // Closing tag ='
              >>
              >> echo $html_header;
              >>
              >> ?>
              >>
              >> If the opening & closing tags are both ' then it works fine, but if the
              >> html script itself contains a ' then i need some way to escape it, no ?[/color]
              >
              > Yes. You should escape it with \ or just use the very versatile
              > heredoc syntax.
              >[color=green]
              >> How should i do it if i had something like <HEAD><TITLE='P HP
              >> foo'></HEAD>?[/color]
              >
              > Option One:
              >
              > $head = '<HEAD><TITLE=\ 'PHP foo\'></HEAD>';
              >
              > Option Two:
              >
              > $head = "<HEAD><TITLE=' PHP foo'></HEAD>";
              >
              > Option Three:
              >
              > $head = <<<ENDOFHEAD
              > <HEAD><TITLE='P HP foo'></HEAD>
              > ENDOFHEAD;[/color]

              Option Four:

              $head = '<HEAD><TITLE=" PHP foo"></HEAD>';

              Although of course this isn't valid HTML as the title tag works like this:

              <title>PHP Foo</title>

              and the tags and attributes should be in lower case because you have defined
              XHTML Script as your document type.

              --
              Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

              Comment

              • Chris Hope

                #8
                Re: How to store HTML code (with &quot; &quot;, ' ') inside a variable in php script ?

                Robin Goodall wrote:
                [color=blue]
                > Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:[color=green]
                >> How should i do it if i had something like <HEAD><TITLE='P HP
                >> foo'></HEAD>?[/color]
                >
                > [nit-picking]
                > Tags and attributes should be lower case
                > Attribute values should be in double quotes no single.
                > <title=...> is not valid html; <title>PHP foo</title> is
                > [/nit-picking][/color]

                You *can* use single quotes. I can't find this referenced anywhere, but I
                just made a test document in both 1.0 Strict and 1.1 and they both
                validated when using single quotes for attribute values.

                --
                Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

                Comment

                • Andy Hassall

                  #9
                  Re: How to store HTML code (with &quot; &quot;, ' ') inside a variable in php script ?

                  On Thu, 11 Nov 2004 14:34:54 +0000, Robin Goodall <anon@somewhere .com> wrote:
                  [color=blue]
                  >Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:[color=green]
                  >>
                  >> How should i do it if i had something like <HEAD><TITLE='P HP foo'></HEAD>?[/color]
                  >
                  >[nit-picking]
                  >Tags and attributes should be lower case[/color]

                  This is not required, and the examples in the HTML specification have the
                  element names in upper case.

                  HTML4.0.1, sec 1.2.1 (Document Conventions, Elements and Attributes):


                  "Element names are written in uppercase letters (e.g., BODY). Attribute names
                  are written in lowercase letters (e.g., lang, onsubmit). Recall that in HTML,
                  element and attribute names are case-insensitive; the convention is meant to
                  encourage readability."

                  HTML4.0.1, sec 3.2.1:


                  "Element names are always case-insensitive."
                  [color=blue]
                  >Attribute values should be in double quotes no single.[/color]

                  Single quotes are perfectly acceptable; they're explicitly allowed in the HTML
                  specification, via the SGML specification:

                  HTML4.0.1, sec 3.2.2:


                  "By default, SGML requires that all attribute values be delimited using either
                  double quotation marks (ASCII decimal 34) or single quotation marks (ASCII
                  decimal 39)."

                  --
                  Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
                  <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

                  Comment

                  • Andy Hassall

                    #10
                    Re: How to store HTML code (with &quot; &quot;, ' ') inside a variable in php script ?

                    On Fri, 12 Nov 2004 08:01:41 +1300, Chris Hope <blackhole@elec trictoolbox.com >
                    wrote:
                    [color=blue]
                    >Robin Goodall wrote:
                    >[color=green]
                    >> Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:[color=darkred]
                    >>> How should i do it if i had something like <HEAD><TITLE='P HP
                    >>> foo'></HEAD>?[/color]
                    >>
                    >> [nit-picking]
                    >> Tags and attributes should be lower case
                    >> Attribute values should be in double quotes no single.
                    >> <title=...> is not valid html; <title>PHP foo</title> is
                    >> [/nit-picking][/color]
                    >
                    >You *can* use single quotes. I can't find this referenced anywhere, but I
                    >just made a test document in both 1.0 Strict and 1.1 and they both
                    >validated when using single quotes for attribute values.[/color]

                    It's defined back in the XML spec; see the two alternatives, one for double
                    quotes and the other for single quotes:



                    --
                    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
                    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

                    Comment

                    • Chris Hope

                      #11
                      Re: How to store HTML code (with &quot; &quot;, ' ') inside a variable in php script ?

                      Andy Hassall wrote:
                      [color=blue][color=green]
                      >>Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:[color=darkred]
                      >>>
                      >>> How should i do it if i had something like <HEAD><TITLE='P HP
                      >>> foo'></HEAD>?[/color]
                      >>
                      >>[nit-picking]
                      >>Tags and attributes should be lower case[/color]
                      >
                      > This is not required, and the examples in the HTML specification have the
                      > element names in upper case.[/color]

                      Well actually in his example he was using XHTML Strict as the document type
                      so tags and attributes *must* be in lower case.

                      --
                      Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

                      Comment

                      • Andy Hassall

                        #12
                        Re: How to store HTML code (with &quot; &quot;, ' ') inside a variable in php script ?

                        On Fri, 12 Nov 2004 08:17:14 +1300, Chris Hope <blackhole@elec trictoolbox.com >
                        wrote:
                        [color=blue]
                        >Andy Hassall wrote:
                        >[color=green][color=darkred]
                        >>>Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:
                        >>>>
                        >>>> How should i do it if i had something like <HEAD><TITLE='P HP
                        >>>> foo'></HEAD>?
                        >>>
                        >>>[nit-picking]
                        >>>Tags and attributes should be lower case[/color]
                        >>
                        >> This is not required, and the examples in the HTML specification have the
                        >> element names in upper case.[/color]
                        >
                        >Well actually in his example he was using XHTML Strict as the document type
                        >so tags and attributes *must* be in lower case.[/color]

                        Yeah, I cancelled the post after seeing it was XHTML (despite the subject
                        saying HTML) but it looks like it was too late and the message got out.

                        --
                        Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
                        <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

                        Comment

                        • Chris Hope

                          #13
                          Re: How to store HTML code (with &quot; &quot;, ' ') inside a variable in php script ?

                          Andy Hassall wrote:
                          [color=blue][color=green][color=darkred]
                          >>> Maxim Vexler <hq4ever (at) 012 (dot) net (dot) il> wrote:
                          >>>> How should i do it if i had something like <HEAD><TITLE='P HP
                          >>>> foo'></HEAD>?
                          >>>
                          >>> [nit-picking]
                          >>> Tags and attributes should be lower case
                          >>> Attribute values should be in double quotes no single.
                          >>> <title=...> is not valid html; <title>PHP foo</title> is
                          >>> [/nit-picking][/color]
                          >>
                          >>You *can* use single quotes. I can't find this referenced anywhere, but I
                          >>just made a test document in both 1.0 Strict and 1.1 and they both
                          >>validated when using single quotes for attribute values.[/color]
                          >
                          > It's defined back in the XML spec; see the two alternatives, one for
                          > double
                          > quotes and the other for single quotes:
                          >
                          > http://www.w3.org/TR/2000/REC-xml-20001006#NT-AttValue[/color]

                          I knew I'd seen it somewhere the other day. Although my eyes normally glaze
                          over when I try to read DTDs...

                          --
                          Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

                          Comment

                          Working...