Skip to content

Tesla News Articles is a PHP application that retrieves and displays news articles about Tesla using the NewsAPI. It fetches recent articles, processes the data, and presents it in a user-friendly format on a webpage.

Notifications You must be signed in to change notification settings

Vishnu8299/New-s-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

New-s-API

Tesla News Articles

This project is a simple web application that fetches and displays the latest news articles about Tesla using the NewsAPI.

Description

The application uses PHP to make a cURL request to the NewsAPI and retrieve news articles about Tesla. The articles are then displayed on a webpage with their titles, descriptions, and links to read more.

Installation

Prerequisites

  • A web server with PHP installed (e.g., Apache, Nginx, XAMPP, WAMP)
  • An API key from NewsAPI

Video-Output :-

news.api.mp4

This HTML document is a simple web page that displays news articles related to "apple" fetched from an external news API. Here's a breakdown of the code:

HTML Structure :

: Declares the document type and version of HTML. : Root element of the document, specifying the language as English. : Contains meta-information about the document. : Sets the character encoding to UTF-8. : Ensures the page is responsive and scales properly on different devices. <title>: Sets the title of the web page as seen in the browser tab. <style>: Contains CSS styles for the page, including font, margins, padding, and link styling.

PHP Code :

: PHP script embedded within the HTML to dynamically fetch and display news articles.

$api_url: The URL of the API endpoint to fetch news articles about "apple". This URL includes parameters for date range, sorting, and an API key.

cURL Initialization:

curl_init(): Initializes a cURL session. curl_setopt(): Sets various options for the cURL session, such as the URL to fetch, returning the transfer as a string, and adding a custom user agent header. curl_exec(): Executes the cURL request and retrieves the response. curl_close(): Closes the cURL session. json_decode($response, true): Decodes the JSON response into a PHP associative array.

if (isset($news_data['articles']) && !empty($news_data['articles'])):

Checks if the 'articles' key exists and is not empty in the decoded response. echo '

Tesla News Articles

'Outputs the main heading. foreach ($news_data['articles'] as $article): Loops through each article in the response and outputs the title, description, and a link to the full article.

Error Handling:

Checks if the API response contains an error status. Displays an error message or a 'No articles found' message if applicable.

How It Works

  • cURL: The PHP script uses cURL to send an HTTP request to the NewsAPI.
  • JSON Handling: The response is decoded from JSON format into an associative array.
  • HTML Output: The news articles are displayed in an HTML list format. Each article includes the title, description, and a link to read more.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

If you have suggestions or improvements, please fork the repository and create a pull request. For major changes, please open an issue first to discuss what you would like to change.

Contact

For any questions or feedback, please reach out to vishnuvardhanv046@gmail.com

Summary:

This document combines HTML and PHP to create a dynamic news feed webpage. It fetches data from the News API, processes it, and displays the results in a user-friendly format. The styling is minimal and focuses on readability and link interactions.

About

Tesla News Articles is a PHP application that retrieves and displays news articles about Tesla using the NewsAPI. It fetches recent articles, processes the data, and presents it in a user-friendly format on a webpage.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages