Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

To determine whether a string contains an HTML entity, you will be concerned with some information that may not be available by inspecting the string contents: the version of HTML, the character set of the HTML document, the character encoding of the string and possibly even the transfer encoding.

This information might be available from the context in which you obtained the string. For example, if you received it from a web server via HTTP protocol, these attributes might have been specified in the HTTP protocol headers. If not, you may have to make some assumptions, which may or may not be correct. If you make incorrect assumptions, you results may not be satisfactory.

For example, the World Wide Web Consortium publishes a full list of character references for HTML 4.01.

Interpreting HTML documents is complicated by the fact that the character encoding can be specified for some elements in an HTML document, at least with HTML 4.01, so you may have to deal with multiple encodings within the same document. Also, the HTML 4.01 specification has this rather cryptic statement: Character references within comments have no special meaning; they are comment data only. So you might also be concerned when checking your string, to know whether it includes or is from the context of a comment.

Your task may be further complicated by the need to deal with documents which were written to be consistent with some version of some popular browser rather than with any of the HTML or other specifications.

All these difficulties aside, if you assume an HTML version and character encoding then you can search for any of the character entities defined in the HTML specification.

Based on the information you have provided thus far, I would say that the solution provided by wspf is a good start and you should use it until you have some particular case for which it does not work.


In reply to Re^4: replace & by ig
in thread replace & by sandy1028

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2023-12-02 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (16 votes). Check out past polls.

    Notices?