- Home /
Retrieving varibale values from a php script?
I understand how to access a webpage using the WWW class and that i can use the echo statement in php to include my variable values in www.text, but how do I seperate these values from the entire string? Thanks in advance.
Answer by flamy · Jul 16, 2012 at 09:30 AM
i use a rough way of doing it by adding a '*' after each variable value and then in unity i use String.Split function to split and parse it. It is a good method if the number of values to be echoed is less.
But proper way of doing it is using XML format. you have to echo your values as a xml formated text and in unity you can use XMLDocument class to extract it back (like this answer). But i dont prefer it since number of variables are low and also it increases the build size by an mb (which is something to worry in mobile platform.)
here is the sample of how i do it using '*' delimiter.
<?php
for($i = 0; $i < 10; $i++)
{
echo $i.'*'; //i am jus printing 10 values here from for loop, this need not be in loop too!.
}
?>
And in the unity3d after getting the text.
//assume www is the object and is yielded with the value from php bfore this step...
string[] temp = www.text.Split("*".ToCharArray());
// and in the temp array you can use parse to get the value back...
int value1= Int32.Parse(temp[0]);
// now value 1 has the first value 0 in it.
This is a simple method to do ... if the number of values are more dont prefer this method, go with XML.
I think the xml method would work better for me because i will be having alot of values. How would I go about doing this?
check ivan's answer in this link for creating xml document in php.... and to retrieve it in unity3d check the link in my answer above..
Your answer
Follow this Question
Related Questions
PHP POST through $_REQUEST with WEBBUILD 1 Answer
WWW Class is acting up 1 Answer
www.data and string conversion to integer 2 Answers
Problem using WWW with PHP and MYSQL 3 Answers
wwwform send an array the right way! 0 Answers