ID: 36710 Updated by: [EMAIL PROTECTED] Reported By: swift at alum dot mit dot edu -Status: Open +Status: Feedback Bug Type: Documentation problem Operating System: Irrelevant PHP Version: Irrelevant New Comment:
Why do you think "a literal backslash needs to be escaped in only two cases: when it appears before a literal single quote and when it is the last character of the string" is "of course incorrect"? It can be escaped on other places too but it NEEDS to be escaped only in these two cases. Current description is perfectly clear and right from my POV and doesn't need to be changed. Previous Comments: ------------------------------------------------------------------------ [2006-03-13 04:52:06] swift at alum dot mit dot edu Argh! This web interface told me I could "edit my submission". That's not fully true, since I can't edit the main text, I can only add to it. So I've now posted two long discussions that differ only by a pair of commas, and I have no way to correct that. The second submission contains the corrected punctuation. ------------------------------------------------------------------------ [2006-03-13 04:48:51] swift at alum dot mit dot edu I quote from the node on strings in the PHP manual (www.php.net/manual/en/language.types.string.php) where it discusses single-quoted strings: I break into sentences which I reference below: (1) To specify a literal single quote, you will need to escape it with a backslash (\), like in many other languages. (2) If a backslash needs to occur before a single quote or at the end of the string, you need to double it. (3) Note that if you try to escape any other character, the backslash will also be printed! (4) So usually there is no need to escape the backslash itself. Sentence (1) is clear, though "will" should be omitted for better clarity. Sentence (2) means that a literal backslash needs to be escaped in only two cases: when it appears before a literal single quote and when it is the last character of the string. This is of course incorrect (it is contradicted by a correct example further down the page whose output is 'You deleted C:\*.*?'). What the author intends to say is much better expressed by the following: "An escaped backslash (\\) likewise specifies a literal backslash, but it is not normally necessary to escape a literal backslash. Escaping a backslash is necessary only when the context would otherwise make the backslash into an escape operator -- that is, when it appears immediately before another backslash or the single quote terminating the string." Sentence (3) is unclear because it is unclear whether the reference of "other" is "backslash" or "single quote" or both. Also "try to escape" is a confusing hypothetical. A good revision would be: "A backslash followed by any character besides a single quote or another backslash is a literal backslash." Sentence (4) is confusing because it's not clear that "the backslash itself" refers to a literal backslash or an escape-operator backslash. Omit this sentence: this section should deal only with how to specify a single quoted string. Discussion of applications of strings (such as regexps) which also use the backslash as an escape operator belongs somewhere else -- or at least should be clearly separate from the discussion of simply how to specify the contents of a string. "Stringing" together the suggested revisions above: To specify a literal single quote, you need to escape it with a backslash (\), like in many other languages. An escaped backslash (\\) likewise specifies a literal backslash, but it is not normally necessary to escape a literal backslash. Escaping a backslash is necessary only when the context would otherwise make the backslash into an escape operator -- that is, when it appears immediately before another backslash or the single quote terminating the string. A backslash followed by any character besides a single quote or another backslash is a literal backslash. ------------------------------------------------------------------------ [2006-03-13 04:43:22] swift at alum dot mit dot edu Description: ------------ I quote from the node on strings in the PHP manual (www.php.net/manual/en/language.types.string.php) where it discusses single-quoted strings: I break into sentences which I reference below: (1) To specify a literal single quote, you will need to escape it with a backslash (\), like in many other languages. (2) If a backslash needs to occur before a single quote or at the end of the string, you need to double it. (3) Note that if you try to escape any other character, the backslash will also be printed! (4) So usually there is no need to escape the backslash itself. Sentence (1) is clear, though "will" should be omitted for better clarity. Sentence (2) means that a literal backslash needs to be escaped in only two cases: when it appears before a literal single quote and when it is the last character of the string. This is of course incorrect (it is contradicted by a correct example further down the page whose output is 'You deleted C:\*.*?'). What the author intends to say is much better expressed by the following: "An escaped backslash (\\) likewise specifies a literal backslash, but it is not normally necessary to escape a literal backslash. Escaping a backslash is necessary only when the context would otherwise make the backslash into an escape operator -- that is when it appears immediately before another backslash or the single quote terminating the string." Sentence (3) is unclear because it is unclear whether the reference of "other" is "backslash" or "single quote" or both. Also "try to escape" is a confusing hypothetical. A good revision would be: "A backslash followed by any character besides a single quote or another backslash is a literal backslash." Sentence (4) is confusing because it's not clear that "the backslash itself" refers to a literal backslash or an escape-operator backslash. Omit this sentence: this section should deal only with how to specify a single quoted string. Discussion of applications of strings (such as regexps) which also use the backslash as an escape operator belongs somewhere else -- or at least should be clearly separate from the discussion of simply how to specify the contents of a string. "Stringing" together the suggested revisions above: To specify a literal single quote, you need to escape it with a backslash (\), like in many other languages. An escaped backslash (\\) likewise specifies a literal backslash, but it is not normally necessary to escape a literal backslash. Escaping a backslash is necessary only when the context would otherwise make the backslash into an escape operator -- that is when it appears immediately before another backslash or the single quote terminating the string. A backslash followed by any character besides a single quote or another backslash is a literal backslash. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=36710&edit=1