Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Special characters in String variable sent from php.

Explorer ,
Feb 12, 2013 Feb 12, 2013

Hello. Assuming that I send some String variable from php into flash:

AS3:

var MyImportedString:String;

var variables_page_text:URLVariables = new URLVariables();

var varSend_page_text:URLRequest = new URLRequest("MyPHP.php");

varSend_page_text.method = URLRequestMethod.POST;

varSend_page_text.data = variables_page_text;


var varLoader_page_text:URLLoader = new URLLoader;

varLoader_page_text.dataFormat = URLLoaderDataFormat.VARIABLES;

varLoader_page_text.addEventListener(Event.COMPLETE, var_comp_page_text);

varLoader_page_text.load(varSend_page_text);

function var_comp_page_text(event:Event):void {

    MyImportedString =  event.target.data.MyVariable;

}

php:

<?php

header('Content-Type: text/html; charset=utf-8');

$MyString = "some tekst &";

print "MyVariable=" . $MyString;

?>

   I've noticed that the special character '&' residing inside String, throws an error:  #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.

  My first thought was, it has something to do with html entities, but other entities (like <> or ") don't throw any error. Besides, the use of php functions like htmlentities(); or html_entity_decode(); doesn't make any difference in this case:

print "MyVariable=" . htmlentities($MyString);

or

print "MyVariable=" . html_entity_decode($MyString);

  I've also noticed that characters like '%', '^', '+' don't show up at all;

  What does it mean? Any ideas?

  Reagards.

TOPICS
ActionScript
2.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Feb 12, 2013 Feb 12, 2013

This function works in general pretty good:

<?php
   
function flash_encode($string)
    {
      
$string = rawurlencode(utf8_encode($string));

      
$string = str_replace("%C2%96", "-", $string);
      
$string = str_replace("%C2%91", "%27", $string);
      
$string = str_replace("%C2%92", "%27", $string);
      
$string = str_replace("%C2%82", "%27", $string);
      
$string = str_replace("%C2%93", "%22", $string);
      
$string = str_replace("%C2%94", "%22", $string);
      
$string = str_replace("%C

...
Translate
Guru ,
Feb 12, 2013 Feb 12, 2013

This function works in general pretty good:

<?php
   
function flash_encode($string)
    {
      
$string = rawurlencode(utf8_encode($string));

      
$string = str_replace("%C2%96", "-", $string);
      
$string = str_replace("%C2%91", "%27", $string);
      
$string = str_replace("%C2%92", "%27", $string);
      
$string = str_replace("%C2%82", "%27", $string);
      
$string = str_replace("%C2%93", "%22", $string);
      
$string = str_replace("%C2%94", "%22", $string);
      
$string = str_replace("%C2%84", "%22", $string);
      
$string = str_replace("%C2%8B", "%C2%AB", $string);
      
$string = str_replace("%C2%9B", "%C2%BB", $string);

       return
$string;
    }
?>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 13, 2013 Feb 13, 2013
LATEST

Thank You 'moccamaximum'.

Ok. So here is the solution (php function posted by 'moccamaximum' does the trick):

AS3:


var MyImportedString:String;

var variables_page_text:URLVariables = new URLVariables();

var varSend_page_text:URLRequest = new URLRequest("MyPHP.php");

varSend_page_text.method = URLRequestMethod.POST;

varSend_page_text.data = variables_page_text;


var varLoader_page_text:URLLoader = new URLLoader;

varLoader_page_text.dataFormat = URLLoaderDataFormat.VARIABLES;

varLoader_page_text.addEventListener(Event.COMPLETE, var_comp_page_text);

varLoader_page_text.load(varSend_page_text);

function var_comp_page_text(event:Event):void {

    MyImportedString =  event.target.data.MyVariable;

     trace(MyImportedString);        // Output:  some text &%^+

}

php:

<?php

header('Content-Type: text/html; charset=utf-8');

$MyString = "some text &%^+";

print "MyVariable=" . flash_encode($MyString);

function flash_encode($string){

 

     $string = rawurlencode(utf8_encode($string));

     $string = str_replace("%C2%96", "-", $string);

     $string = str_replace("%C2%91", "%27", $string);

     $string = str_replace("%C2%92", "%27", $string);

     $string = str_replace("%C2%82", "%27", $string);

     $string = str_replace("%C2%93", "%22", $string);

     $string = str_replace("%C2%94", "%22", $string);

     $string = str_replace("%C2%84", "%22", $string);

     $string = str_replace("%C2%8B", "%C2%AB", $string);

     $string = str_replace("%C2%9B", "%C2%BB", $string);

     return $string;
}

?>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines