Author Topic: PHP - 99 Bottles of Beer Program  (Read 2575 times)

0 Members and 1 Guest are viewing this topic.

Offline Rytiou

  • Noob Zombie
  • VIP
  • Knight
  • *
  • Posts: 199
  • Cookies: 45
  • EZ's Noob
    • View Profile
PHP - 99 Bottles of Beer Program
« on: October 20, 2013, 03:11:49 pm »
So I've been learning php for a little bit and I decided I wanted to make a simple program to test what I learnt. I know this is nothing exciting really but I wanted to make something simple from scratch without a book telling me what to do. If you can tell me how I did on this 99 bottles of beer program I'd really appreciate it :).


Code: [Select]
<?php


// Sets the initial amount of beer
$count 99;


// Prints the lyrics while count is greater than or equal to 1
while ($count >= 1)
{
echo $count.' bottles of beer on the wall, '.$count.' bottles of beer. <br>';
echo 'Take one down and pass it around, '.($count 1).' bottles of beer on the wall';
echo '<br>';

// Decreases count by one
$count --;
}


?>
Quote from: Evilzone IRC
<EZBot> life, you're so lame we decided to change your nick to Rytiou's bitch.
<EZBot> Rytiou is lord of the fags and will suck dicks for shells.

Offline Fur

  • Knight
  • **
  • Posts: 216
  • Cookies: 34
    • View Profile
Re: PHP - 99 Bottles of Beer Program
« Reply #1 on: October 20, 2013, 03:54:29 pm »
Not bad, could use pre-decrement though:
Code: [Select]
echo 'Take one down and pass it around, ' . --$count . ' bottles of beer on the wall';
echo '<br>';

Offline Rytiou

  • Noob Zombie
  • VIP
  • Knight
  • *
  • Posts: 199
  • Cookies: 45
  • EZ's Noob
    • View Profile
Re: PHP - 99 Bottles of Beer Program
« Reply #2 on: October 20, 2013, 04:17:55 pm »
Well  I tried doing that but what ended up happening was the number was decreasing by two rather than one. And when I remove the bottom one but keep the one you put in it does this:

http://gyazo.com/954cc33babf58434114597c2cd910905
Quote from: Evilzone IRC
<EZBot> life, you're so lame we decided to change your nick to Rytiou's bitch.
<EZBot> Rytiou is lord of the fags and will suck dicks for shells.

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: PHP - 99 Bottles of Beer Program
« Reply #3 on: October 20, 2013, 05:32:08 pm »
Isen't the point of the 99-bottles-of-beer song in code to make it as small as possible? Here is what I got on short notice:

[gist]anonymous/7071149[/gist]
« Last Edit: October 20, 2013, 05:33:21 pm by ande »
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline Rytiou

  • Noob Zombie
  • VIP
  • Knight
  • *
  • Posts: 199
  • Cookies: 45
  • EZ's Noob
    • View Profile
Re: PHP - 99 Bottles of Beer Program
« Reply #4 on: October 20, 2013, 05:55:06 pm »
Isen't the point of the 99-bottles-of-beer song in code to make it as small as possible? Here is what I got on short notice:

[gist]anonymous/7071149[/gist]
Well this was the shortest possible way that I could think of with my current knowledge. Also, if you're trying to show me an example it's either not there or it's just my browser.
Quote from: Evilzone IRC
<EZBot> life, you're so lame we decided to change your nick to Rytiou's bitch.
<EZBot> Rytiou is lord of the fags and will suck dicks for shells.

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: PHP - 99 Bottles of Beer Program
« Reply #5 on: October 20, 2013, 06:57:45 pm »
Well this was the shortest possible way that I could think of with my current knowledge. Also, if you're trying to show me an example it's either not there or it's just my browser.

You need to enable javascript. Jesus, what is it with people and having javascript disabled..


EDIT: Direct link: https://gist.github.com/anonymous/7071149#file-gistfile1-php
« Last Edit: October 20, 2013, 06:58:01 pm by ande »
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: PHP - 99 Bottles of Beer Program
« Reply #6 on: October 20, 2013, 06:59:16 pm »
You need to enable javascript. Jesus, what is it with people and having javascript disabled..

Pretty good security practice, if you ask me.
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline Rytiou

  • Noob Zombie
  • VIP
  • Knight
  • *
  • Posts: 199
  • Cookies: 45
  • EZ's Noob
    • View Profile
Re: PHP - 99 Bottles of Beer Program
« Reply #7 on: October 20, 2013, 07:11:44 pm »
You need to enable javascript. Jesus, what is it with people and having javascript disabled..


EDIT: Direct link: https://gist.github.com/anonymous/7071149#file-gistfile1-php
Aah didn't even think about that. Guess I still have a bunch to learn. Thanks for showing me man :).
Quote from: Evilzone IRC
<EZBot> life, you're so lame we decided to change your nick to Rytiou's bitch.
<EZBot> Rytiou is lord of the fags and will suck dicks for shells.

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: PHP - 99 Bottles of Beer Program
« Reply #8 on: October 20, 2013, 07:18:57 pm »
Pretty good security practice, if you ask me.

Globally disabling javascript does more harm than good if you ask me. If you need to disable javascript to be secure while browsing, you should consider adapting a new browsing habit.
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline Rytiou

  • Noob Zombie
  • VIP
  • Knight
  • *
  • Posts: 199
  • Cookies: 45
  • EZ's Noob
    • View Profile
Re: PHP - 99 Bottles of Beer Program
« Reply #9 on: October 20, 2013, 07:20:15 pm »
Globally disabling javascript does more harm than good if you ask me. If you need to disable javascript to be secure while browsing, you should consider adapting a new browsing habit.
Well the only reason I had disabled was because I was testing a firefox addon and I forgot that I had it on still.
Quote from: Evilzone IRC
<EZBot> life, you're so lame we decided to change your nick to Rytiou's bitch.
<EZBot> Rytiou is lord of the fags and will suck dicks for shells.

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: PHP - 99 Bottles of Beer Program
« Reply #10 on: October 20, 2013, 09:20:06 pm »
The very last verse will be grammatically wrong, won't it?

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: PHP - 99 Bottles of Beer Program
« Reply #11 on: October 20, 2013, 11:50:15 pm »
The very last verse will be grammatically wrong, won't it?

Indeed, needs to say bottle not bottles. Should be simple enough.
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline BrokenSyntax

  • /dev/null
  • *
  • Posts: 10
  • Cookies: 2
    • View Profile
Re: PHP - 99 Bottles of Beer Program
« Reply #12 on: October 26, 2013, 10:57:39 pm »
Code: [Select]
for ($i = 100; $i > 0; $i--) {
   echo sprintf('%1$d %3$s of beer on the wall, %1$d %3$s of beer.<br>Take one down and pass it around, %2$d %4$s of beer on the wall<br>', $i, ($i-1), ($i==1) ? 'bottle' : 'bottles', (($i-1)==1) ? 'bottle' : 'bottles');
}

This will, to my knowledge, fix the grammar in the last verse
« Last Edit: October 26, 2013, 10:57:54 pm by BrokenSyntax »