Jump to content

wee493

Members
  • Posts

    87
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

wee493's Achievements

Member

Member (2/5)

0

Reputation

  1. I'm creating a quiz type application where there are hundreds of quetsions in a database and they are all tagged with chapter and sub chapters in my review material where they've come from. I have a page where users can select which chapters/sub chapters to answer questions from. I need help on the best way to save which questions the user will be doing and incrementing to the next question through them taking the quiz. With a normal quiz it's easy to increment id + 1 to the next question, but in this case I assume I need to store an array of what questions they're doing in a session? Or should I store it in the database with a pointer to a quiz session id? What would you recommend? Any ideas are appreciated, thank you!
  2. Sorry, I figured it out $date = date("z"); echo ($date - (4 * floor($date/4)));
  3. I have 4 links that I want to show a different one every 24 hours, I would just put the links in an array and chose a random one, but it needs to be a different one every day. I'm having trouble thinking of how to do this without a mysql db
  4. If you visit my site at http://joshoak.es/test you'll see that the URL changes to "http://joshoak.es/test/#/screens/d12245cc-1680-458d-89dd-4f0d7fb22724" I can see in the document where that comes from <script type="text/javascript">jQuery(document).ready(function(){jimMain.init("screens/d12245cc-1680-458d-89dd-4f0d7fb22724");});</script> If I remove that, the page doesn't load. This isn't my site, so I don't know a lot about the structure, but a friend asked me if I could fix this. Do you have any suggestions? Thanks!
  5. I'm wanting to download and entire clone of a webpage using php. Save the page, js, css, and images. If I use fopen() or file_get_contents() it only saves the main page and not the linked assets. Is there another method to doing this?
  6. It seems that the get_headers function is what I'm looking for. Here's a demo code for anyone interested function expand_url($url) { $h = get_headers($url); // if no redirect header then return the original url return isset($h['Location']) ? $h['Location'] : $url; }
  7. I'm using the Twitter streaming API and receiving a feed of recently tweeted links. I'm trying to create an index of popular links. I would like to expand all the shortened links. I'm using the bit.ly API to expand the bitly links as that accounts for almost exactly 1/3 of the links, but I still have 2/3 of other links that could be expanded. I have over 600,000 links in the database and about 200,000 are bit.ly links. So, this means I still have 400,000 links to expand, though not all links can be expanded. For example twitpic links are usually not shortened. But anyways, I'm using the funciton below to expand URLs right now function untinyurl($tinyurl) { $url = parse_url($tinyurl); $host = $url['host']; $port = isset($url['port']) ? $url['port'] : 80; $query = isset($url['query']) ? '?'.$url['query'] : ''; $fragment = isset($url['fragment']) ? '#'.$url['fragment'] : ''; if (empty($url['path'])) { return ''; } else { $path = $url['path']; } $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, "http://$host:$port".$path.$query.$fragment); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // seconds curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); $response = curl_exec($ch); if ($response === false) { $tinyurl = ''; } curl_close($ch); $lines = explode("\r\n", $response); foreach ($lines as $line) { if (stripos($line, 'Location:') === 0) { list(, $location) = explode(':', $line, 2); return ltrim($location); } } if (strpos($response, 'HTTP/1.1 404 Not Found') === 0) { return ''; } return $tinyurl; } The only thing is it can take a second or more for this to work. I was wondering if there is any quicker way to do this? I know I'm going to have to ping the servers because there is not an index of shortened urls, so my speeds will depend on the remote servers.
  8. I need some help parsing this text file. I've tried a few things, but had trouble as it's not actually json data. I've tried various str_replaces and things along those lines, but I would like to be able to output this into a table with the Steam id, time, name, and reason. If someone can just point me in the right direction i'd be fine coding myself! Thanks! "STEAM_0:0:18130940" { "admin" "(Console)" "unban" "1274151724" "time" "1273546924" "name" "-=SAS=- Death Master511" "reason" "Gcombat on spawn/Server Crash Attempts 1 week appeal at halania.com" } "STEAM_0:1:6428933" { "time" 1273619777 "unban" 1273706177 "admin" "TornadoChas3r(STEAM_0:0:19768725)" "name" ".:T.¥:. TRÅÑŒ (CRYSTAL)" "reason" "RDM/ 1 day Ban \"You had Enough Warnings\" / :" } Here's basically what I have right now, which does not work too well $myFile = "bans.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); $rowsArr = explodeRows($theData); for($i=0;$i<count($rowsArr);$i++) { $lineDetails = explodeTabs($rowsArr[$i]); echo "<br>Steam ID: " . $lineDetails[0]; echo "<br>Surname : " . $lineDetails[1]; echo "<br>Tel Number : " . $lineDetails[2]; echo "<br><br>"; } function explodeRows($data) { $rowsArr = explode("\n", $data); return $rowsArr; } // Explode the columns according to tabs function explodeTabs($singleLine) { $tabsArr = explode("\t", $singleLine); return $tabsArr; }
  9. I've managed to get it working for the most part by doing $text = str_replace("\n", '<br>', $get); print($text);
  10. That did not help. I just cant echo php, plain text is fine. I've even tried base 64 encoding/decoding with no luck.
  11. I've found that my problem is <?PHP tags. When "<?PHP" or "?>" is saved in a database an d tried to echo it messes things up. How can I input and output PHP tags without it trying to run the code?
  12. even using that code returned nothing. It's like it's getting a result but having trouble echoing it
  13. Trying the following displays nothing include('includes/session.php'); $result = mysql_result(mysql_query("SELECT text FROM text WHERE id = '1'"), 0); echo $result; This is what is saved in that row on the DB <?PHP $name = \'Wee493\'; $string = \'Hello World this is \'.$name.\'!\'; echo $string; ?>
  14. I'm wanting to save snipets into an sql database and be able to display them later (Similar to pastebin and those types of sites). I've already setup a table with the type set to text and have syntax highlighting taken care of. On the way in I'm doing mysql_real_escape_string() on the text but when I try to echo it out I have minimal luck. Can anyone offer any suggestions/help?
  15. Thank you so much! I've made a few minor changes and adapted it to my need. The efficiency is not a really problem, I most likely will never go over four characters as (if my math is correct) this should give me almost 3,000,000 unique results. I'm getting better at PHP, just need to learn a little bit more about lines like this $string[$x] = $string[$x] === strtoupper($string[$x]) ? strtolower($string[$x]) : strtoupper($string[$x]);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.