From a066660764583d754d3f91e4e095cc78d69b0075 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Thu, 1 Jun 2023 08:52:18 -0500 Subject: add get_user function --- index.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'index.php') diff --git a/index.php b/index.php index 2359934..bca506d 100644 --- a/index.php +++ b/index.php @@ -130,6 +130,52 @@ function get_stories($api_url, $inline_title) { return $html_output; } +/** +*Extract a user's profile from Hacker News API and format in HTML +* +* @access public +* @author cmc +* @param string $api_url The API endpoint to use for extraction +* @param string $inline_title The

title to use in the HTML +* @return string $html_output The formatted HTML result of stories from the API +*/ +function get_user(string $api_url, string $inline_title) { + $response_raw = file_get_contents($api_url); + if (is_null($response_raw) || $response_raw == "null") { + $html_output .= '

ERROR: User not found.

'; + return $html_output; + } else { + $response = json_decode($response_raw, true); + } + + $html_output = '

' . $inline_title . '

'; + $html_output .= '

About: ' . $response['about'] . '

'; + $html_output .= '

Karma: ' . $response['karma'] . '

'; + $html_output .= '

Created: