- Home /
Retreiving php value using WWW
I have the following php script and would like to get the echo into unity. However, when I do www.text
,it gives me the HTML text instead of the echoed value. Can someone point out to me where did I go wrong?
<?php
$a = 'apple';
$b = 'cider';
$c = 'drink';
echo $c;
?>
In Unity I use:
var www : WWW = new WWW("My address");
yield www;
Debug.Log(www.text);
It gives me the whole html page after www.text.
EDIT: It looks like someone had a similar problem but not solved.
Answer by Kiloblargh · Jul 19, 2013 at 07:04 AM
That's what www.text should give you, "drink" followed by the whole page.
You could use String.Split to trim off everything but the first word.
Or you can use WWWForm with $POST to just send a value to the PHP script and get the echo value back.
I don't see "drink." According to this you simply use the WWW.text
method to get the echoed value. Btw, the first word that I get is...
<!DOCTYPE HT$$anonymous$$L PUBLIC "-//W3C//DTD HT$$anonymous$$L 3.2 Final//EN">
...but I have no HT$$anonymous$$L at all in my .php file
Yes, are you sure that you are actually requesting your php file?
@kiloblargh @ Bunny83 Your comments solved my problem. I exposed the wrong link in the Inspector, but I only changed the link (url) in the code. The wrong link does not contain the .php file, only pointed to the folder where the .php file was. After making sure the variable in the inspector point to the right address and "..requesting your php file." the problem was solved! Thank you! I like to upvote your comments but unfortunately my rating is too low to do that. Greatly appreciated!