Posts Tagged ‘rawurldecode()’

Adobe Air, SQLite, and apostrophes

Tuesday, March 16th, 2010

I’m currently developing an Air application and I run into a problem inserting file names with apostrophe (because apostrophe are used as string delimiter). There are several ways to handle this problem. You can add two apostrophes, and Jake Churchill has made a function for this.

While working with back-end I’ve used PHP’s utf8_encode edit: I meant rawurlencode() quite a lot, and AS3 has several similar functions, but there is only one that encodes apostrophes, and it’s called escape(). So what you can do is escape() the strings to be inserted into SQLite, and use unescape() after receiving the string back from the database.

Here is an example with escape() and unescape() used in AS3:

var testString:String = &quot;This is a test &#8216; with &#8216; several apostrophes&#8217;&quot;;<br />
trace( testString ); // This is a test &#8216; with &#8216; several apostrophes&#8217;<br />
testString = escape( testString );<br />
trace( testString ); //This%20is%20a%20test%20%27%20with%20%27%20several%20apostrophes%27<br />
testString = unescape( testString );<br />
trace( testString ); //This is a test &#8216; with &#8216; several apostrophes&#8217;

Here is an example with rawurlencode and rawurldecode() used in PHP:

$testString = &quot;This is a test &#8216; with &#8216; several apostrophes&#8217;&quot;;<br />
 echo $testString . &quot;&lt;br /&gt;&quot;; // This is a test &#8216; with &#8216; several apostrophes&#8217;<br />
 $testString = rawurlencode( $testString );<br />
 echo $testString . &quot;&lt;br /&gt;&quot;; // This%20is%20a%20test%20%27%20with%20%27%20several%20apostrophes%27<br />
 $testString = rawurldecode( $testString );<br />
 echo $testString . &quot;&lt;br /&gt;&quot;; // This is a test &#8216; with &#8216; several apostrophes&#8217;