익명 ·
2023.12.24 ·
조회 4
news api test
<p>--------------------노출방지--------------------</p><p><?php<br>$apiKey = "c9c3a565936242c9955729ca458e3faa"; // Replace this with your actual API key<br><br>if ($_SERVER["REQUEST_METHOD"] == "POST") { // Check if a search query was submitted via POST <br>request<br> $inputText = urlencode($_POST["query"]); // Encode the user's search text and store it in a <br>variable<br><br> $url = <br>"<a href="https://api.cognitive.microsoft.com/bing/v7.0/news/search?q=%7B$inputText%7D&key=%7B$apiKey%7D" rel="nofollow">https://api.cognitive.microsoft.com/bing/v7.0/news/search?q={$inputText}&key={$apiKey}</a>";<br><br> $ch = curl_init();<br> curl_setopt($ch, CURLOPT_URL, $url);<br> curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br> curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);<br><br> $response = curl_exec($ch);<br> curl_close($ch);<br><br> $jsonResponse = json_decode($response, true); // Decode the JSON response<br><br> if (isset($jsonResponse["value"])) { // Check if articles were found in the API response<br> $articles = $jsonResponse["value"];<br><br> echo "<h1>Search Results:</h1>";<br> foreach ($articles as $article) {<br> echo "<h2>" . htmlspecialchars($article["title"]) . "</h2>";<br> echo "<p><a href='" . htmlspecialchars($article["url"]) . "' target='_blank'>" . <br>htmlspecialchars($article["description"]) . "</a></p>";<br> }<br> } else { // Display a message if no articles were found<br> echo "<h1>No search results found.</h1>";<br> }<br>} else { // If the page was not called via POST request, display a form for users to input <br>their query text<br> ?><br> <!DOCTYPE html><br> <html lang="en"><br> <head><br> <meta charset="UTF-8"><br> <meta name="viewport" content="width=device-width, initial-scale=1.0"><br> <title>Bing News Search</title><br> </head><br> <body><br> <h1>Search for news articles:</h1><br> <form method="post"><br> <label for="query">Enter your search query:</label><br> <input type="text" name="query" id="query" required><br> <button type="submit">Search</button><br> </form><br> </body><br> </html><br> <?php<br>}<br>?><br> {<br><br> "status": "ok",<br> "Total results": 7378,<br> -<br> "Articles": [<br> -<br> {<br> -<br> "Source": {<br> "id": null,<br> "name": "ETF Daily News"<br> },<br> "저자": "Market Beat News",<br> "title": "Tesla, Inc. (NASDAQ:TSLA) SignalPoint Asset Management LLC에서 판매한 주식",<br> "Description": "SignalPoint Asset Management LLC reduced its stake in Tesla Inc (NASDAQ:TSLA – Free Report) by 0.6% in the third quarter, according to the most recent 13F filing with the Securities and Exchange Commission. The company owned 7,368 shares.",<br> "url": "<a href="https://www.etfdailynews.com/2023/12/23/tesla-inc-nasdaqtsla-shares-sold-by-signalpoint-asset-management-llc/" rel="nofollow">https://www.etfdailynews.com/2023/12/23/tesla-inc-nasdaqtsla-shares-sold-by-signalpoint-asset-management-llc/</a> ",<br> "urlToImage": "<a href="https://www.americanbankingnews.com/wp-content/timthumb/timthumb.php?src=https" rel="nofollow">https://www.americanbankingnews.com/wp-content/timthumb/timthumb.php?src=https</a> ://<a href="http://www.marketbeat.com/logos/tesla-inc-logo.png?v=20221020135629&w=240&h=240&zc=2" rel="nofollow">www.marketbeat.com/logos/tesla-inc-logo.png?v=20221020135629&w=240&h=240&zc=2</a> ,<br> "publishedAt": "2023-12-23T16:38:50Z",<br> "Content": "SignalPoint Asset Management LLC reduced its stake in Tesla Inc (NASDAQ:TSLA – Free Report) by 0.6% in the third quarter. S… [+6334 chars]"<br> },<br> -<br> { {To analyze and type text into the input and press the search button next to the input to output the search results (title, image, title, and link (link to title), please implement using php,js,html5 etc.) My api key is c9c3a565936242c9955729ca458e3faa</p><p><br></p>