Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Madswint · Jun 14, 2014 at 12:24 PM · arraywwwphp

Get array from a php, put it into an array in Unity?

This is my php script. I'm trying to make it get all songs in that folder on my website, then send it to unity, so unity can make a playlist and stream the songs one by one, to save memory. I've barely done any php, how would I get the array from the php and put it into one in Unity? It's probably simple, but google doesn't help me much atm.

 if ($handle = opendir('Playlist/')) {
     echo "Directory handle: $handle\n";
     echo "Entries:\n";
 
    
     while (false !== ($entry = readdir($handle))) {
         echo "$entry\n";
     }
 
     closedir($handle);
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by PouletFrit · Jun 14, 2014 at 01:54 PM

Sending data between php scripts and unity is normaly done using Get or Post Request via WWW or WWWForm classes. And you can't send an array using that method, however you could send CSV (comma-separeted values) representing an array.

Add a comma in between all of your "echos".

 while (false !== ($entry = readdir($handle))) {
     echo $entry . ",";
 }

And then in Unity you can easily retreive that data using a simple string.Split(',') and convert it in an array

 string url = "http://example.com/script.php";
 WWW www = new WWW(url);
 yield return www;
 
 string[] songNames = www.text.Split(',');

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Madswint · Jun 14, 2014 at 02:09 PM 0
Share

Could you write this in javascript? Thanks a lot btw! Sucks you cant directly get it from an array, but this will do pretty much the same.

avatar image PouletFrit · Jun 14, 2014 at 06:16 PM 0
Share

it would pretty much be the same I think... not really sure though

 var url = "http://example.com/script.php";
 var www : WWW = new WWW (url);
 yield www;

 var songnames = www.text.Split(",");

or something along thoses lines

avatar image Madswint · Jun 14, 2014 at 07:02 PM 0
Share

I just got it converted, it doesn't work though. Here is how it is:

 var getPlaylist : String = "http://shuleii.dk/Guardian/getfiles.php";
 var songNames : String[];
 
 
 function Start () {
 
 
 var www : WWW = new WWW (getPlaylist);
 yield www;
 var songNames =  www.text.Split(","[0]);
  
 }
 


avatar image PouletFrit · Jun 15, 2014 at 06:46 PM 0
Share

remove the [0] from Split

Split will return an array so if you want to access his first value use:

 songNames[0]

if you wanted to only store the first value of the array that www.text.Split return in the variable songNames:

 var songNames = www.text.Split(",")[0];
avatar image Madswint · Jun 15, 2014 at 07:31 PM 0
Share

It wont allow me to erase the 0 >.<

I get the error Assets/[$$anonymous$$it] Scripts/Radio.js(15,32): BCE0023: No appropriate version of 'String.Split' for the argument list '(String)' was found.

Can I get you to write the script like I did above with the changes you mean? I'm either doing it wrong, or it doesn't work like that in Javascript? Thanks !! :>

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Array Dump to String for Send via WWW 1 Answer

wwwform send an array the right way! 0 Answers

Putting array nr. 1 in a string ;o? 2 Answers

About renting the host for the game 1 Answer

Unity - MySQL data loss 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges