PHP String conversion to Array for Flash

Converting a string in PHP to array and sending back to Flash

Here you learn how to convert arrays of strings formed in a PHP file to an ordered XML file, which can be recognized and read in Flash. Enter strings into the textfield and push the "SUBMIT" button. Strings can be like "hhh""llll""mmmm" or "ggggg","KKKKKK","jjjj" or ggggg KKKKK jjjj or some other combination. This is a simple alternative if you don't use amfphp.

The PHP file

Below the PHP file is shown. What is done is the array of individual strings is stripped of some characters mainly quotation marks and commas and then the array is formed. The array is then converted to a XML list and send back to Flash.


$input = $_GET['input'];
$output  = $input;

	// we strip off some characters and commas from the strings.

$output = str_replace('\"\"', ",", $output);
$output = str_replace('\"', "", $output);
$output = str_replace("\'\'", ",", $output);
$output = str_replace("\'", "", $output);
$output = str_replace(",", " ", $output);

	// we create an array of the strings.

$words = explode(' ', $output);

	// The array is converted to an XML List.


	// This function creates the XML list.

function decode($myWords)
	for($i=0; $i<count($myWords); $i++)
	return $nodes;

	// The XML List is returned to Flash.

echo "$myXML";



In the Flash file the incoming XML list is converted to an XML file. Any individual string can then be detected. Below is only the part of the script, where the XML file is formed.

private function completeHandler(event:Event):void
	var myData:XML = new XML("<data>"+unescape("</data>");
	for (var i:int=0; i<myData.members.length(); i++)