I have been trying get data out of new reddit post, but theres limitation where you cant get data from more than 100 posts. can anybody help me to getover this below is my code
$output = "";
for($digit=0; $digit<1000; $digit+=25){
$jsondata = trim(file_get_contents("http://www.reddit.com/new/.json?count=$digit"));
$json = json_decode($jsondata, true);
$moviesChildren = $json['data']['children'];
foreach($moviesChildren as $movie){
$output .= '"'.$movie["data"]["title"].'", ';
$output .= $movie["data"]["ups"].", ";
$output .= $movie["data"]["num_comments"].", ";
$output .= $movie["data"]["domain"]."\n\r";
$output .= "<br />";
}
}
echo $output;
What is the output you get, and what are you expecting instead?
First off, you will want to follow the API rules about authentication or else you'll be quickly limited, and possibly banned.
Listings have before and after attributes to help with pagination. You will need to pass those into your subsequent GETs in order to fetch the next page.
Related
Hi I have a Api list that is been generated using php here is the code that is been used to generate the list
<html>
<title> API LIST</title>
<body>
<?php
$jsondata = file_get_contents("api_link");
$json = json_decode($jsondata, true);
$output = "<ul>";
foreach($output['A'] as $schools){
$output .= "<li>".$schools['name']."</li>";
}
$output .="</ul>";
echo $output;
?>
the list is populated successfully but how can i add a link to the list so that when a user click on one of the items it opens a particular linked page here are the ways i have tried
$output .= "<li ".$schools['name']."</li>";
$output .= "<li>".$schools['name']. "</li>";
$output .= "<li>".$schools['name']."</li>";
I don't know where or how to add the a href code
Use
$output .= '<li>'.$schools['name'].'</li>';
You just need some changes in your code.You can try for
$output .= '<a href=https://www.google.com'.$schools['name'].'><li>'.$schools['name'].'</li></a>';
As per the comments you can use . to concatenate(join) the string and variable in php.
Not sure I worded the title correctly, I'm unsure of what this is called.
I have a while loop which is populated by an SQL query
while($row = $result->fetch_assoc()){
$Tchannel = $row['chan'];
echo '<img src="https://static-cdn.jtvnw.net/previews-ttv/live_user_'.$Tchannel.'-320x180.jpg" alt="Thumbnail"><br />';
echo '<p>';
}
My problem is that when the page loads it does it in sections. I've seen other websites populate these straight away on page load. How would I replicate something like this?
See Example: http://puu.sh/oTh6v/73446c0c15.jpg
Could this be what you meant to achieve...? And by the way, the opening Paragraph Tag:< p > could contribute to some unexpected &/or sluggish behaviour since it was just opened without being closed anywhere in your code... I commented it out... You may try to see if it helps....
<?php
// CREATE A STRING VARIABLE TO HOLD THE ENTIRE OUTPUT TILL YOU ARE READY TO RENDER IT TO THE STREAM...
$strOutput = "";
while($row = $result->fetch_assoc()){
$Tchannel = $row['chan'];
$strOutput .= '<img src="https://static-cdn.jtvnw.net/previews-ttv/live_user_' . $Tchannel . '-320x180.jpg" alt="Thumbnail"><br />';
// WHY DO YOU NEED THIS OPENING PARAGRAPH TAG? WHERE IS IT CLOSED IN YOUR CODE?
//echo '<p>';
}
// RENDER THE OUTPUT
echo $strOutput;
?
If you need the images wrapped in paragraph tags, you can do it differently:
<?php
// CREATE A STRING VARIABLE TO HOLD THE ENTIRE OUTPUT TILL YOU ARE READY TO RENDER IT TO THE STREAM...
$strOutput = "";
while($row = $result->fetch_assoc()){
$Tchannel = $row['chan'];
$strOutput .= '<p>'; // <== OPEN A PARAGRAPH
$strOutput .= '<img src="https://static-cdn.jtvnw.net/previews-ttv/live_user_' . $Tchannel . '-320x180.jpg" alt="Thumbnail"><br />';
$strOutput .= '</p>'; // <== CLOSE THE PARAGRAPH
// OR ALL IN ONE LINE:
// $strOutput .= '<p><img src="https://static-cdn.jtvnw.net/previews-ttv/live_user_' . $Tchannel . '-320x180.jpg" alt="Thumbnail"><br /></p>';
}
// RENDER THE OUTPUT
echo $strOutput;
?>
I'm trying to store a xml as string in a variable so that I can store it in my database.
$xml = "<root>";
foreach(...){
$xml .= "<user id='$id'/>";
}
$xml .= "</root>";
When I echo it, it's not displayed at all as if my web brower reads it as html tag. It doesn't even look like $xml is storing those as texts. Now, I'm trying to do it with DOMDocument... not not quite successful yet. Any tips? :(
Edited my stupid += mistakes..
PHP uses a . as a concatenate operator, or a .= as a shortcut, not a + or +=.
$xml = "<root>";
foreach(...){
$xml .= "<user id='$id'/>";
}
$xml .= "</root>";
I hope someone can help me with this. The code below is from a WordPress Plugin. From the plugin option page I am entering some simple html -
<h3>Showname</h3><p>with DJ Top</p>
The code below ($showname) is used (a WordPress shortcode) to display what I've entered, but it actually displays the HTML rather than processing it i.e displaying the HTML header and paragraph.
Can anyone point me in the direction so $showname processes the HTML rather than just printing it out verbatim tags and all.
Many thanks
Rob
function showtime_schedule_handler($atts, $content=null, $code=""){
global $wpdb;
global $showtimeTable;
//Get the current schedule, divided into days
$daysOfTheWeek = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$schedule = array();
$output = '';
foreach ($daysOfTheWeek as $day) {
//Add this day's shows HTML to the $output array
$showsForThisDay = $wpdb->get_results( $wpdb->prepare ( "SELECT * FROM $showtimeTable WHERE dayOfTheWeek = '$day' ORDER BY startTime" ));
//Check to make sure this day has shows before saving the header
if ($showsForThisDay){
$output .= '<h2>'.$day.'</h2>';
$output .= '<ul class="showtime-schedule">';
foreach ($showsForThisDay as $show){
$showName = $show->showName;
$startClock = $show->startClock;
$endClock = $show->endClock;
$linkURL = $show->linkURL;
if ($linkURL){
$showName = ''.$showName.'';
}
$output .= '<li><strong>'.$startClock.'</strong> - <strong>'.$endClock.'</strong>: '.$showName.'</li>';
}
$output .= '</ul>';
}
}
return $output;
}
You're outputting with a variant of the text/plain MIME type. You'll need to send it out with a default header (text/html) in order for the browser to parse it properly.
For instance:
<?php
header('Content-Type: text/html', true);
echo showtime_schedule_handler($atts, $content);
?>
Instead of
return $output;
try
return html_entity_decode($output);
having an annoying issue with getting xml data from a url
if i set "$file_show_title" to a single word (comes from the url passed from another page) then all works fine. if if "$file_show_title" is 2 words (tried encoding the url also) then it failed to find the address.
im not the best at explaining but i hope that this is enough for someone to help me please
thanks
$url = file_get_contents("http://www.thetvdb.com/api/GetSeries.php?seriesname=".$file_show_title);
$xml = simplexml_load_string($url);
$seriesid = $xml->Series[0]->seriesid;
$seriesbanner = $xml->Series[0]->banner;
$seriesname = $xml->Series[0]->SeriesName;
$serieslanguage = $xml->Series[0]->language;
$seriesfist_aired = $xml->Series[0]->FirstAired;
$seriesoverview = $xml->Series[0]->Overview;
echo '<img src="/images/'.$seriesbanner.'">'."<br />";
echo $seriesname."<br />";
echo $seriesid."<br />";
echo $serieslanguage."<br />";
echo $seriesfist_aired."<br />";
echo $seriesoverview."<br />";
What you needed was urlencode Please see http://php.net/manual/en/function.urlencode.php for more information
Example
$url = file_get_contents("http://www.thetvdb.com/api/GetSeries.php?seriesname=" . urlencode("Prison Break"));
Now Use
$url = file_get_contents("http://www.thetvdb.com/api/GetSeries.php?seriesname=" . urlencode($file_show_title));
I hope it helps