[PHP] htmlentities -- can it skip tags

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Re: [PHP] htmlentities -- can it skip tags

    Justin French wrote:
    > Hi all,
    >
    > I need to convert some text from a database for presentation on
    > screen... as per usual, characters like quotes and ampersands (&) are
    > giving me grief. the obvious answer is to apply htmlspecialchars(), BUT
    > this also converts all < and > into &lt; and &gt; signs, which destroys
    > the html mark-up within the text.
    >
    > Is there a non-tag equivalent of htmlspecialchars(), or do I need to
    > build one?
    You'll have to build one.

    If you know what characters are causing trouble, you could just use
    str_replace on them. Or you could use htmlspecialchars() and then run
    str_replace to convert &lt; and &gt; back into brackets.

    You could also use get_html_translation_table() to get the conversions,
    remove the < and > conversion elements of the array and then use strtr()
    to do the conversion.


    --
    ---John Holmes...

    Amazon Wishlist: [url]www.amazon.com/o/registry/3BEXC84AB3A5E/[/url]

    php|architect: The Magazine for PHP Professionals – [url]www.phparch.com[/url]
    John W. Holmes Guest

  2. Similar Questions and Discussions

    1. How to treat template tags as comment tags?
      Hi all, I am using DW MX to edit templates for a FreeMarker application. The template tag fromat is like so: <ul> <#list birds as bird>...
    2. encodings and htmlentities...
      Hi, I have a seamingly simple problem: My databse contains following character: µ. When I put it into xml, xml breaks. I tried using...
    3. htmlentities adds slashes - why?
      Folks, I'm using Apache/1.3.28 (SuSE 7.1, kernal 2.4) with PHP/4.3.2. I have the following code to help cleanse form data. function...
    4. Using ParseChildren attribute to load child tags - VS removes tags
      I am building a poll control, nested in the tag I have child tags to setup the poll options. Everything works fine, but when I edit a property in...
    5. preg_replace + htmlentities
      Sandy Lewanscheck wrote: Replace the "dangerous" chars with "something else" in the replace_url function (like ''), then apply replace_url,...
  3. #2

    Default Re: [PHP] htmlentities -- can it skip tags

    On Monday, September 15, 2003, at 12:58 PM, John W. Holmes wrote:
    > Justin French wrote:
    >
    >> Hi all,
    >> I need to convert some text from a database for presentation on
    >> screen... as per usual, characters like quotes and ampersands (&) are
    >> giving me grief. the obvious answer is to apply htmlspecialchars(),
    >> BUT this also converts all < and > into &lt; and &gt; signs, which
    >> destroys the html mark-up within the text.
    >> Is there a non-tag equivalent of htmlspecialchars(), or do I need to
    >> build one?
    >
    > You'll have to build one.
    >
    > If you know what characters are causing trouble, you could just use
    > str_replace on them. Or you could use htmlspecialchars() and then run
    > str_replace to convert &lt; and &gt; back into brackets.
    Which is what I just did as a 'patch' :)

    > You could also use get_html_translation_table() to get the
    > conversions, remove the < and > conversion elements of the array and
    > then use strtr() to do the conversion.
    I like that idea a LOT.

    Thanks John!


    Justin
    Justin French Guest

  4. #3

    Default Re: [PHP] htmlentities -- can it skip tags

    On Monday, September 15, 2003, at 12:58 PM, John W. Holmes wrote:
    > Justin French wrote:
    >
    >> Hi all,
    >> I need to convert some text from a database for presentation on
    >> screen... as per usual, characters like quotes and ampersands (&) are
    >> giving me grief. the obvious answer is to apply htmlspecialchars(),
    >> BUT this also converts all < and > into &lt; and &gt; signs, which
    >> destroys the html mark-up within the text.
    >> Is there a non-tag equivalent of htmlspecialchars(), or do I need to
    >> build one?
    >
    > You'll have to build one.
    >
    > If you know what characters are causing trouble, you could just use
    > str_replace on them. Or you could use htmlspecialchars() and then run
    > str_replace to convert &lt; and &gt; back into brackets.
    Which is what I just did as a 'patch' :)

    > You could also use get_html_translation_table() to get the
    > conversions, remove the < and > conversion elements of the array and
    > then use strtr() to do the conversion.
    I like that idea a LOT.

    Thanks John!


    Justin
    Justin French Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139