htmlentities et al.: relationship between quote_style and charset parameters (was: character switch)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Dunlop

    htmlentities et al.: relationship between quote_style and charset parameters (was: character switch)

    (Crossposted and followups set. Hope you don't mind Markus.)

    The Manual expresses the parameters of htmlentities as:

    string string [, int quote_style [, string charset]]



    The meaning is unambiguous: the first parameter, "string", must be
    present; the second parameter, "quote_styl e", is optional; and the
    final parameter, "charset", is optional too, but its presence
    requires the, prima facie, ought-to-be dispensable second
    parameter.

    Why does the existence of the charset parameter depend on the
    existence of the quote_style parameter? What's the connection?

    --
    Jock
  • Paulus Magnus

    #2
    Re: htmlentities et al.: relationship between quote_style and charset parameters (was: character switch)

    "John Dunlop" <john+usenet@jo hndunlop.info> wrote in message
    news:MPG.19ee59 d8c86fe7c098977 f@news.freeserv e.net...[color=blue]
    > (Crossposted and followups set. Hope you don't mind Markus.)
    >
    > The Manual expresses the parameters of htmlentities as:
    >
    > string string [, int quote_style [, string charset]]
    >
    > http://www.php.net/manual/en/function.htmlentities.php
    >
    > The meaning is unambiguous: the first parameter, "string", must be
    > present; the second parameter, "quote_styl e", is optional; and the
    > final parameter, "charset", is optional too, but its presence
    > requires the, prima facie, ought-to-be dispensable second
    > parameter.
    >
    > Why does the existence of the charset parameter depend on the
    > existence of the quote_style parameter? What's the connection?[/color]

    You can't pass an optional 3rd parameter if there isn't a second parameter,
    otherwise it would be the second parameter. :)

    Paulus


    Comment

    • Markus Ernst

      #3
      Re: htmlentities et al.: relationship between quote_style and charset parameters (was: character switch)

      "John Dunlop" <john+usenet@jo hndunlop.info> schrieb im Newsbeitrag
      news:MPG.19ee59 d8c86fe7c098977 f@news.freeserv e.net...[color=blue]
      > (Crossposted and followups set. Hope you don't mind Markus.)[/color]

      No problem; I am not really a usenet specialist...
      [color=blue]
      > The Manual expresses the parameters of htmlentities as:
      >
      > string string [, int quote_style [, string charset]]
      >
      > http://www.php.net/manual/en/function.htmlentities.php[/color]

      That's interesting; I had not seen this before.
      [color=blue]
      > The meaning is unambiguous: the first parameter, "string", must be
      > present; the second parameter, "quote_styl e", is optional; and the
      > final parameter, "charset", is optional too, but its presence
      > requires the, prima facie, ought-to-be dispensable second
      > parameter.
      >
      > Why does the existence of the charset parameter depend on the
      > existence of the quote_style parameter? What's the connection?[/color]

      The quote_style parameter only defines which quotes to replace (only double
      quotes, both single and double, or none of them), there is no way to define
      what they are going to be replaced by. Double quotes are replaced by &quot;
      and single ones by &#039;

      I tried this with Latin-1 and Chinese Big 5 encodings, there was no
      difference.

      So I think it is just the name of the parameter "quote_styl e" which is
      confusing, as you don't set the style. You can't set them to &rsquo; or
      &raquo; or ASCII something, or whatever. So it seems to be independent from
      the encoding but rather just provide a possibility for coders to handle
      quotes in connection with their coding style, as in some cases you might
      want to keep a " as it is and not replace it by &quot;

      --
      Markus


      Comment

      • John Dunlop

        #4
        Re: htmlentities et al.: relationship between quote_style and charset parameters (was: character switch)

        Markus Ernst wrote:
        [color=blue]
        > So I think it is just the name of the parameter "quote_styl e" which is
        > confusing, as you don't set the style.[/color]

        I hadn't actually considered that. But, with further pondering, I
        believe the parameter's name could've conceivably been better
        chosen. Dare I say a misnomer even?
        [color=blue]
        > So [quote_style] seems to be independent from the encoding [...][/color]

        Yes, that's the crux of the matter. The conversion of quotation
        marks *is* independent of the character set.

        Why must I explicitly set the quote_style value -- even if that
        value is equivalent to its default -- whenever I wish to use a
        different character set? Why is quote_style not optional whenever
        I change character sets?

        IOW, why is the parameters' notation not:

        string string [, int quote_style] [, string charset]

        --
        Jock

        Comment

        • Gerhard Fiedler

          #5
          Re: htmlentities et al.: relationship between quote_style and charset parameters (was: character switch)

          On Thu, 9 Oct 2003 11:28:01 +0100, John Dunlop wrote:[color=blue]
          >IOW, why is the parameters' notation not:
          >
          >string string [, int quote_style] [, string charset][/color]

          Not possible in PHP. That would require something like a strongly
          typed language (e.g. Java or C++) and overloading. This is not really
          what PHP is.

          Comment

          • John Dunlop

            #6
            Re: htmlentities et al.: relationship between quote_style and charset parameters (was: character switch)

            Gerhard Fiedler wrote:
            [color=blue][color=green]
            > >string string [, int quote_style] [, string charset][/color]
            >
            > Not possible in PHP. That would require something like a strongly
            > typed language (e.g. Java or C++) and overloading. This is not really
            > what PHP is.[/color]

            Right. A slip-up on my part then. Thank you.

            After further reading, I notice that The Manual's notes about "How
            to read a function definition (prototype)" says next to nothing
            about optional parameters. Someone without much knowledge, reading
            that page -- me to a tee! -- might benefit from supplementary
            documentation.


            So, RTFM was unsuccessful. And so was googling, which brought up
            page upon page of clues about optional parameters and variable-
            length parameter lists in *user-defined* functions. The Manual
            already explains those in enough detail IMO. Ho hum.


            Thanks again, Gerhard.

            --
            Jock

            Comment

            • Gerhard Fiedler

              #7
              Re: htmlentities et al.: relationship between quote_style and charset parameters (was: character switch)

              On Thu, 9 Oct 2003 17:35:24 +0100, John Dunlop wrote:
              [color=blue][color=green][color=darkred]
              >> >string string [, int quote_style] [, string charset][/color]
              >>
              >> Not possible in PHP. That would require something like a strongly
              >> typed language (e.g. Java or C++) and overloading. This is not really
              >> what PHP is.[/color]
              >
              >Right. A slip-up on my part then. Thank you.[/color]

              No problem.

              I actually didn't include everything above. What I sometimes do with
              user-defined functions in such cases (but that's not what the PHP
              internal functions do) is to pass in an associative array. This has
              the same effect as named arguments, and then the order is not relevant
              anymore, and whan needs to be supplied is no longer restricted by the
              language syntax, but only by the program logic.

              Comment

              Working...