 Welcome back to the channel. In our previous video, we made a short call called take-a-press domains and essentially what that did was that every time we reloaded our page, we got back information from our XML data point. This data is nice and okay, but there is one problem. In all the different languages every time the art symbol is used, it has a particular meaning to it. We shal not be able to use the art attributes as a string or as a node in the future videos that we'll make and that is especially with things like JavaScript. So right now I need to convert this into a more palatable PHP array, but I'm also going to strip everything down so that we have something that is more predictable as an object. So how do I do that? I'm going to come back to our code here. I'll scroll down to our function. In here, I'm going to come and say let us return and we're going to return a function called convert XML to PHP array and that will be a function and in this function we are going to pass our body response and basically that's going to allow us to get everything that we have here, cut it and then I should be able to write a new function here called convert XML to PHP array. We can now define our function here and I'm going to just paste what we cut from up here previously. So I'm going to use more of the error log and then I'm going to comment out the front end vadamp because it might give us a lot of issues yet the error log just works straight out of the box. Now I'll copy this PHP variable name and I'll paste it here. Since we are passing this body response in here, I'm going to copy the same thing and I'll pass it here to this function so that they are working well. We don't have a PHP error. In this function what we have is we're using a PHP function called simple XML load string and this is basically going to get this XML string and convert it into an object. Now once we have that as an object, we are encoding it into JSON and then thereafter we are decoding it and that is the value that we get every time we reload the other page. So I'm going to error log our PHP and we can see the types or the data types that we have and we can be able to loop through the different arrays and so on to get the information that we need. So I'm going to go back to our browser after saving this. I'll reload this page and you see right here we have nothing displaying but if we go to our editor, go to the debug.log, you'll see that we have this whole chunk of information coming back. We have two object items, one which is the art attributes and then we have these domains right here. Of course this is telling us what's happening. We have a status of one and then we are also checking which is basically the same thing we are doing in the function. We know that we are checking for availability and this availability is being checked for on the XML data point. I've just renamed this function so that it's more clear and then once we are in here, we can now start writing and saying we need to get the PHP object and we are looking for the domains object at this particular case in time. Why is that? We just want to get this node that has all our information coming back. So we are going to loop through this object because it now has an array of domains and we're going to save for each of this object as a single domain and what we can do here is we can error log this, error log the domain and see what comes back after looping through this. Of course I know we are going to get this chunk of information but I would like you to visually see that. So I'll scroll down here. I'm going to go back to our editor. I'll hit reload, come back to the editor and you'll see that now we have this information showing up. It's just what we had here but we've gone a step inside and we're getting the different objects. So since this is an array of data as it's telling us here, we need to loop through this again and say let's duplicate this and in this particular case we're going to say let's get each domain from here, let's get each domain and we're going to say we're going to represent that as domain info and we can copy this and say let's error log the domain info. Close off this for each statement, save it, let's go back and scroll up just a bit, go to our browser, reload this call from the API, go back to the editor and you'll see now we are getting the individual pieces of information and they are all standard class objects. So we need to get this item which is the at attributes from each one of these domain infos. So we're going to say the domain info and we want to get the object which is called the at attributes. Now you can see that my editor is already screaming at me and telling me this has a different meaning. Can you please fix that? So I'm going to wrap this in kali brackets to say this is PHP but this is actually just a string. So I'm going to wrap that and say this is how we get the attributes and I'm going to wrap this and say this is the domain log. Let's get the domain log, I'll go back to our browser, hit refresh, go back into our editor and you'll see that when we scroll down now we have this standard object that gives us the name and the availability. I'll come back to this and say for the domain log in order for us to get the name which we'll just say is equal to name is equal to domain log and we're going to map on that and say we want to get the name and then I'll duplicate this and just say the availability is just going to be avail avail and we can get that from this object right here. So at this point we can actually just say we're going to have formatted underscore domains and we shall say this is equal to an empty array and so each time we come here we want to array push and in PHP this allows us to add information to another array. So we reference the array we want to have information and in here we want to pass an array of data whereby we have name and we're going to map this to the name here. So I just need to move this just above so that we can see them correctly. I'll say we need to map that to the name and the other thing is we're going to say availability is going to be mapped onto dollar sign avail right here. We're going to move this error log down here and I just want to get our formatted domains and I want to error log it and see that we have the correct simple piece of data that we wanted from all along. So save this come back to the browser hit one reload and I'll come back here to the editor scroll to the bottom and you're going to see that we have an array that has another array inside and we basically just have names right here. So this would be a little bit easier and simpler to use inside our JavaScript because we have more predictable nodes of data coming through. At this point I'm just going to return formatted domains because this function is doing one thing and one thing alone and it's allowing us to return that data. So I can click save here. I can come back here and say if I want to vadamp this information that's okay. I'm just going to cut this return we're going to call these domains and say is equal to that and comment this and say let's vadamp our domains and then after doing that we should be able to return domains. So I'm going to come back here. I'll reload this. We have a simple array with other simpler array items inside it which is domain name and availability. So this will be a lot easier to use and you're going to see how this all plays out. So I'll just clean this up a bit. I'll move these to one straight line and that is simply to answer the call from our coding standards of WordPress and this will look a little bit nicer. I'm going to remove this because we don't need it anymore and this is what we need to get us to move forward. So in the next video I'm going to show you how we can connect the data that is actually being returned and how we can add this down here visually so that when we click this button on our search form the information is being displayed as coming back from the API. In order to do this we shall be using Ajax and if you want to see that then jump into the next video.