Re: Decoding html entities
Re: Decoding html entities
- Subject: Re: Decoding html entities
- From: Matt Neuburg <email@hidden>
- Date: Mon, 12 Jun 2006 07:51:02 -0700
- Thread-topic: Decoding html entities
On Mon, 12 Jun 2006 10:19:38 +0200, Conor Dearden <email@hidden>
said:
>I answered this question for someone before:
>
>http://www.cocoabuilder.com/archive/message/cocoa/2006/5/12/163330
>
>In your case I believe the PHP function is quite limited in its translation
>and Adam is correct and all you need to do is:
>
> NSSrting *aString = [objectDictionary objectForKey:@"name"];
>
> NSMutableString *convertedHTMLString = [NSMutableString string];
> [convertedHTMLString setString:aString];
>
> [convertedHTMLString replaceOccurrencesOfString:@"&" withString:@"&"
>options:NSLiteralSearch range:NSMakeRange(0, [convertedHTMLString length])];
>
> [convertedHTMLString replaceOccurrencesOfString:@"""
>withString:@"\"" options:NSLiteralSearch range:NSMakeRange(0,
>[convertedHTMLString length])];
>
> [convertedHTMLString replaceOccurrencesOfString:@"<" withString:@"<"
>options:NSLiteralSearch range:NSMakeRange(0, [convertedHTMLString length])];
>
> [convertedHTMLString replaceOccurrencesOfString:@">" withString:@">"
>options:NSLiteralSearch range:NSMakeRange(0, [convertedHTMLString length])];
>
> [convertedHTMLString replaceOccurrencesOfString:@"'"
>withString:@"'" options:NSLiteralSearch range:NSMakeRange(0,
>[convertedHTMLString length])];
That's a common mistake (I see it several times among the comments on the
PHP manual page pointed to earlier). The mistake is that you're doing it in
the wrong order, since you will convert "&lt;" to ">", and that's
incorrect - indeed, the whole purpose of writing "&lt;" would presumably
be to prevent that from happening (e.g. you're trying to represent the
phrase "<" to the reader). The correct way is always to convert &
*last*, not first. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden