- Home /
Other
Why do I get a newline (\n br) while sending a simple string from php to Unity c#
Hi everyone,I'm trying to understand how I can interract between Unity and PHP so I started with simple stuff but it's been 3 days that I'm fighting with this and can't find a solution, I have this simple code:
string url = "http://localhost/login.php";
IEnumerator PhpRequest()
{
WWW webRequest2 = new WWW(url);
yield return webRequest2;
print(webRequest2.text);
}
and GUI button that calls the couroutine on click...
Then I have the "login.php" file with a simple echo instruction:
<?php echo'a';?>
When I test it I get in Unity console a free line then a, I know this because I tried to execute something if(webRequest2.text == "a") and it didnt work, then I tried print("x"+webRequest2.text) and I got :
x
a
Thanks for reading, and I'm hopelessly waiting for an answer and hoping to finally move on to interesting stuff :'(
have you tried setting php content-type so it treats it as text?
Answer by Adamcbrz · Jun 19, 2013 at 06:01 PM
I tested what your issue and i can't reproduce it. With what you have said I would assume that one of two things are going on.
1) In your php file you have extra line breaks at the beginning of the file. 2) Your web-server is is treating it as html or some other content type that would cause the line break. It could also be something configured with your web-server.