Imagine to have an output from PHP organized in a certain way, let's say like this-->
nights_no=3&leav=30.07.2010&foo=bar&arriv=27.07.2010&free_rooms=~records_total_noØ15~typename(1)ØConfort~remarks(1)ØThe amenities of the roomaa
include a mini-bar, internet connection, TV with satellite, telephone, safe, mobile air-conditioning, hairdryer and so on.
No. of people this room: 4 people max
No. of adults this room: 3 adults max.
Anne O\'Brieni
~description(1)ØAs our main interest consists at offering our guests uniquely aesthetical and admirably organized settings, \r\nwe have created a place in Rome mixing contemporary and luxury facilities with traditional design objects and furniture that offers authentic insular nobility and amazing room facilities in Rome.\r\nSaintGeorge hotel offers you exclusive room facilities in Rome for your ultimate comfort and relaxation and personalized services to satisfy all your needs.~maxadults(1)Ø7~image(1)Øcool-ideas-decorating-baby-.jpg~maxchildren(1)Ø3~pricepernight(1)Ø67.00~room_id(1)Ø13~room_number(1)Ø3~typename(2)ØConfort~remarks(2)ØThe room include a mini-bar, internet connection, TV with satellite, telephone, safe, mobile air-conditioning, hairdryer and so on.No. of people this room: 7 people max
No. of adults this room: 8 adults max.
Anne O'Brienn
~description(2)ØAs our main interest consists at offering our guests uniquely aesthetical and admirably organized settings, \r\nwe have created a place in Rome mixing contemporary and luxury facilities with traditional design objects and furniture that offers authentic insular nobility and amazing room facilities in Rome.\r\nSaintGeorge hotel offers you exclusive room facilities in Rome for your ultimate comfort and relaxation and personalized services to satisfy all your needs.~maxadults(2)Ø7~image(2)Øcool-ideas-decorating-baby-.jpg~maxchildren(2)Ø3~pricepernight(2)Ø67.00~room_id(2)Ø14~room_number(2)Ø4~typename(3)ØConfort~remarks(3)ØThe pretty room include a mini-bar, internet connection, TV with satellite, telephone, safe, mobile air-conditioning, hairdryer and so on.No. of people this room: 4 people max
No. of adults this room: 3 adults max.
Anne O'Brienn
~description(3)ØAs our main interest consists at offering our guests uniquely aesthetical and admirably organized settings, \r\nwe have created a place in Rome mixing contemporary and luxury facilities with traditional design objects and furniture that offers authentic insular nobility and amazing room facilities in Rome.\r\nSaintGeorge hotel offers you exclusive room facilities in Rome for your ultimate comfort and relaxation and personalized services to satisfy all your needs.~maxadults(3)Ø7~image(3)Øcool-ideas-decorating-baby-.jpg~maxchildren(3)Ø3~pricepernight(3)Ø67.00~room_id(3)Ø15~room_number(3)Ø5~typename(4)ØStandard~remarks(4)ØThe beautiful room include a mini-bar, internet connection, TV with satellite, telephone, safe, mobile air-conditioning, hairdryer and so on.No. of people this room: 4 people max
No. of adults this room: 3 adults max.
Anne O\'Brienn
~description(4)ØSaintGeorge hotel offers you exclusive room facilities in Rome for your ultimate comfort and relaxation and personalized services to satisfy all your needs.rnAs our main interest consists at offering our guests uniquely aesthetical and admirably organized settings, rnwe have created a place in Rome mixing contemporary and luxury facilities with traditional design objects and furniture that offers authentic insular nobility and amazing room facilities in Rome.~maxadults(4)Ø3~image(4)Øcity-view-room-hotel-renew-.jpg~maxchildren(4)Ø2~pricepernight(4)Ø45.00~room_id(4)Ø16~room_number(4)Ø1~typename(5)ØStandard~remarks(5)ØThe demo room include a mini-bar, internet connection, TV with satellite, telephone, safe, mobile air-conditioning, hairdryer and so on.No. of people this room: 4 people max
No. of adults this room: 3 adults max.
Anne O'Brienn
~description(5)ØSaintGeorge hotel offers you exclusive room facilities in Rome for your ultimate comfort and relaxation and personalized services to satisfy all your needs.rnAs our main interest consists at offering our guests uniquely aesthetical and admirably organized settings, rnwe have created a place in Rome mixing contemporary and luxury facilities with traditional design objects and furniture that offers authentic insular nobility and amazing room facilities in Rome.~maxadults(5)Ø3~image(5)Øcity-view-room-hotel-renew-.jpg~maxchildren(5)Ø2~pricepernight(5)Ø45.00~room_id(5)Ø17~room_number(5)Ø2~typename(6)ØSuperior~remarks(6)ØThe amenities of the room this text is just to show that you can put HTML formatted tags in here. The supported tags are br,p,b,i~description(6)ØSuperior SaintGeorge hotel offers you exclusive room facilities in Rome for your ultimate comfort and relaxation and personalized services to satisfy all your needs.we have created a place in Rome mixing contemporary and luxury facilities with traditional design objects and furniture that offers insular nobility and amazing room facilities in Rome.~maxadults(6)Ø5~image(6)ØCrowne-Plaza-LGA-room.jpg~maxchildren(6)Ø3~pricepernight(6)Ø67.00~room_id(6)Ø18~room_number(6)Ø1~typename(7)ØJunior Suite~remarks(7)ØThe amenities of the room include a mini-bar, internet connection, TV with satellite, telephone, safe, mobile air-conditioning, hairdryer and so on.
No. of people this room: 4 people max
No. of adults this room: 3 adults max.
Anne O'Brienn
~description(7)ØJunior Suite 6 well â?? furnished guest apartments up to 30 square meters with living â?? room. All rooms feature extraordinary amenities including cable televisions with international and special channels, telephone with AT T direct, high â?? speed Internet access, mini â?? bars and underfloor heating. Rooms with King â?? Size beds are available. Comfortable bathrooms are equipped with shower cabins. Room â?? service is available daily.~maxadults(7)Ø5~image(7)ØDanielWebsterRoom_1.jpg~maxchildren(7)Ø1~pricepernight(7)Ø66.00~room_id(7)Ø19~room_number(7)Ø1~typename(8)ØExecutive~remarks(8)ØThe amenities of the room include a mini-bar, internet connection, TV with satellite, telephone, safe, mobile air-conditioning, hairdryer and so on.No. of people this room: 4 people max
No. of adults this room: 3 adults max.
Anne O'Brienn
~description(8)ØExecutive 4 stylish guest rooms up to 35 square meters equipped with the most modern comforts including high â?? speed Internet access, telephone with international direct dial, mini â?? bar, television package with PAY-TV. All Executive rooms offer King â?? Size beds. Comfortable bathrooms are equipped with modern bathes. Room â?? service is available daily.~maxadults(8)Ø6~image(8)Ødecor_room02_boracay.jpg~maxchildren(8)Ø1~pricepernight(8)Ø12.00~room_id(8)Ø20~room_number(8)Ø1~typename(9)ØRoyal~remarks(9)Ønothing to remark~description(9)ØRoyal
~maxadults(9)Ø4~image(9)Ødecor_room03_boracay.jpg~maxchildren(9)Ø2~pricepernight(9)Ø80.00~room_id(9)Ø21~room_number(9)Ø1~typename(10)ØRoyal~remarks(10)Øroyal rema
~description(10)ØRoyal
~maxadults(10)Ø4~image(10)Ødecor_room03_boracay.jpg~maxchildren(10)Ø2~pricepernight(10)Ø80.00~room_id(10)Ø22~room_number(10)Ø2~typename(11)ØRoyal~remarks(11)Øremark~description(11)ØRoyal
~maxadults(11)Ø4~image(11)Ødecor_room03_boracay.jpg~maxchildren(11)Ø2~pricepernight(11)Ø80.00~room_id(11)Ø23~room_number(11)Ø789~typename(12)ØYoung Generation~remarks(12)Øyoung gen room
~description(12)ØYoung Generation rem~maxadults(12)Ø7~image(12)Øhotel-florida-room-200.jpg~maxchildren(12)Ø5~pricepernight(12)Ø55.00~room_id(12)Ø24~room_number(12)Ø1~typename(13)ØBingo Room~remarks(13)Øremarks~description(13)ØBingo Room here you can play Bingo.~maxadults(13)Ø5~image(13)Øgrand-hyatt-bali-room2.jpg~maxchildren(13)Ø3~pricepernight(13)Ø44.00~room_id(13)Ø25~room_number(13)Ø1~typename(14)ØBungalow~remarks(14)Øbunga rem
~description(14)ØBungalow
~maxadults(14)Ø8~image(14)ØHotelRoom.jpg~maxchildren(14)Ø2~pricepernight(14)Ø22.00~room_id(14)Ø26~room_number(14)Ø2~typename(15)ØStar type room~remarks(15)ØStar type room
~description(15)ØStar type room
~maxadults(15)Ø2~image(15)Økkroom.jpg~maxchildren(15)Ø1~pricepernight(15)Ø48.00~room_id(15)Ø27~room_number(15)Ø1
function ExecuteQueryforEverything():void
{
var sending:URLRequest = new URLRequest ("./booking/everything.php");
sending.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.websitecode = escape(uniquewebsitecode);
sending.data = variables;
var GalleryVar_to_send:URLLoader = new URLLoader (sending);
GalleryVar_to_send.addEventListener(Event.COMPLETE, EverythingonVarsLoaded);
GalleryVar_to_send.addEventListener(Event.CANCEL, EverythingonVarsCancel);
GalleryVar_to_send.dataFormat = URLLoaderDataFormat.TEXT;
GalleryVar_to_send.load(sending);
}
If we use GalleryVar_to_send.dataFormat = URLLoaderDataFormat.TEXT; we avoid many of the errors due to pairs variable-value not matching each other. Of course we have to parse all the output coming from e.target.data once we are in the definition of the function EverythingonVarsLoaded(e:Event) .
By using GalleryVar_to_send.dataFormat = URLLoaderDataFormat.TEXT; instead of variabiles we are not only free from strange unicode errors, we will also have the output from PHP directly in the string e.target.data, so, when we get errors from php we'll be aware of them straight away.
We could after that call a function that would parse all this big output from PHP looking for the value associated with the variable maxchildren(7). The value of this by looking at the output above is 1, this because we can clearly see a piece of that output below ..........nielWebsterRoom_1.jpg~maxchildren(7)Ø1~pricepernight(7)Ø66.00~ro.........
Accordingly to the way the data are displayed from PHP the variable pricepernight(7) has value 66.00, that means within each couple of characters Ø ~ the value of the variable defined before Ø. Have a better look at the PHP output, you'll see that.
The following code is for searching within the block we got from PHP all the values of the variabiles we want.
function PhpParse(var_to_search_for:String, where_to_search:String):String
{
var start_pos:int; // helps in getting the values delimited from ~ and =
var end_pos:int;
//trace("where_to_search.length=" + where_to_search.length);
//trace(var_to_search_for);
start_pos= where_to_search.indexOf("~" + var_to_search_for + "Ø") + var_to_search_for.length + 2;
//trace("where_to_search.charAt(start_pos + 1)" + where_to_search.charAt(start_pos + 1) + "]]");
if (start_pos == -1)
{
trace("PhpParse function ERROR on+++" + var_to_search_for + "+++string" );
return "-99999"; // exit and return
}
end_pos = where_to_search.indexOf("~",where_to_search.indexOf("~"+var_to_search_for+"Ø") + 1) ;
//trace("end_pos=" + end_pos);
if (( end_pos > where_to_search.length) || ( end_pos == -1)) end_pos= where_to_search.length;
return where_to_search.substring(start_pos ,end_pos)
} // end function PhpParse
This function outputs the value associated with the var sent as input to this function: example: we could perform a trace of this PhpParse("maxchildren(7)", e.target.data)