Jump to content

  •  

  • iBotModz CBox


    Photo

    PHP Object problem


    • Please log in to reply
    3 replies to this topic

    #1 Rogue Modder

    Rogue Modder

      Class of 2008

    • VIP

    • 1,328 posts
    • Joined: 02-January 09
    • Gender:Male
    • Location:London, UK

    Posted 22 January 2011 - 06:31 PM

    the Reach API returns a object for emblum, but i want a string (url string). How do i convert the object into a string. (lack of debugging in PHP gets on my tits).

    Alex.

    #2 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 22 January 2011 - 06:50 PM

    Pass $information['Player']['ReachEmblem'] from /player/details/nostats API, to this neat function, which I ended up posting on haloreachapi.net.

    Then you get returned a string of the URL. You can specify the size, but otherwise its defaulted to 70.

    private function _getEmblem($subject, $size = 70)
    	{
    
    		/* check for array */
    		if (is_array($subject))
    		{
    			/* thanks: http://www.haloreachapi.net/wiki/Emblems */
    
    			/* Emblem to Link */
    			$bi = $subject['background_index'];
    			$fi = $subject['foreground_index'];
    			$fl = $subject['flags'] ? 0 : 1;
    			$c0 = $subject['change_colors'][0];
    			$c1 = $subject['change_colors'][1];
    			$c2 = $subject['change_colors'][2];
    			$c3 = $subject['change_colors'][3];
    
    			/* Send it back */
    			return "http://www.bungie.net/Stats/emblem.ashx?s=$size&0=$c0&1=$c1&2=$c2&3=$c3&fi=$fi&bi=$bi&fl=$fl&m=3";
    
    		} else
    		{
    			return "";
    		}
    
    }
    


    #3 Rogue Modder

    Rogue Modder

      Class of 2008

    • VIP

    • 1,328 posts
    • Joined: 02-January 09
    • Gender:Male
    • Location:London, UK

    Posted 22 January 2011 - 06:55 PM

    Ahh, i saw that on the API wiki, but im very new to PHP. so i had no idea what todo with it.

    Thanks :)

    Update:
    I'm getthig this error;
    "Fatal error: Cannot use object of type stdClass as array in ***/reachstats.php on line 49"

    How are you calling the function?

    Edited by Xerax, 22 January 2011 - 07:14 PM.


    #4 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 22 January 2011 - 07:39 PM

    O your using it as objects instead of arrays.

    Find where you read the json, and append true into the parameters. Boom done.