counting php

by 14 replies
16
Ok well I am tring to do is count to 100 but the catch is what I want to do is every number of 3 like 3 6 9 12 ect.. needs to say fizz and all the numbers 5 10 ect.. needs to say buzz and all the numbers 15 30 45 ect.. needs to say fizzbuzz I have tried to do it but i am stumped I can sloopy code it but i want it so if i want it to do it up to 500 or a 1000 i can not just 100 cause thats sloopy I really have not delt with counting in php I have a prgrep script that will replace but i want to set up so it counts by 2 4 6 8 then i can fig it out but this has got me stumped

thank you
#programming #counting #php
  • lol are you on codeacademy?
    • [1] reply
    • no I am just tring to do it for myself code quize i gave myself its driving me boonkers that i can not fig out
  • This page on php.net might help you.
  • $c=0;
    while ($c<100){
    $c=$c+3;
    echo "$c<br>";
    }
  • There are lots of ways to write this, but here's one:



    WF is stripping out half the code so I took a screenshot and inserted that.

    % is the modulus operator and returns the remainder of integer division.

    A multiple of 3 will have a remainder of 0 when divided by 3.

    A multiple of 5 will have a remainder of 0 when divided by 5.

    By checking both those conditions in series, you'll print "Fizz" then "Buzz" when the number is a multiple of both 3 and 5.
    • [ 1 ] Thanks
    • [2] replies
    • wow thank you so much I suck at doing math in php would like to make beeter in my skills know i got to fig the fizzbuzz lol :confused:
    • You guys are awsome thank you so much I was going boonnkers with it and all I have say awsome

      thank you
  • for($i = 0 ; $i < $num ; $i++)
    {
    if($i%3 == 0 && $i%5== 0)
    echo "fyzzbyzz";
    else if($i%3 == 0)
    echo "fyzz";
    else if($i%5 == 0)
    echo "byzz";
    }

    Hope the above code will help you understand
  • Sorry jiffy I should have read the entire message.
    • [ 1 ] Thanks
  • Thank you very much You got it right the first time thank you for the code I totaly got it I just haven't been coding for 6 months or so being rusty and tring to get back into it the first code i wrote for this was a pregrep and replace but was having a prob with numbers on it. I was wondering when you a pregrep replace with a number do you need to do something like this '/3/' or is it '{3}' just never had to do a number in a pregrep.
  • Do you mean preg_replace, which means PCRE (perl-compatible regular expression) regular expression replace? Pregrep isn't a word or nickname for anything.

    If you want to match the number 3, the pattern is just 3. No slashes, no curly braces. {3} would tell the regular expression matcher to repeat the previous pattern 3 times. The whole pattern, though, needs to be surrounded by a delimiter, which can be any character you want. The forward slashes are commonly chosen.

    Regular expressions are a complex topic all of their own.

    If you just want to replace a literal string with a different literal string (i.e. change all the "3"s to something else), you don't need a regular expression. Use str_replace.



    • [2] replies
    • Hello dan Thank You very much for all the info Srry for miss using words for code I have not gone to college for program I have taught everything I know from ie and firefox there is no school up hear in montana that teaches php but you can get your zend in kalispell which I am tring to do but tring to teach myself and I know I have a ton to learn lol

      Thank you very much
      • [1] reply
    • \
      Ha ha thats funny I read his message where he was saying pregrep and Im like. .. hmm never hear of that .. I started thinking that it was some kind of PHP grep type thing I never knew about

Next Topics on Trending Feed

  • 16

    Ok well I am tring to do is count to 100 but the catch is what I want to do is every number of 3 like 3 6 9 12 ect.. needs to say fizz and all the numbers 5 10 ect.. needs to say buzz and all the numbers 15 30 45 ect.. needs to say fizzbuzz I have tried to do it but i am stumped I can sloopy code it but i want it so if i want it to do it up to 500 or a 1000 i can not just 100 cause thats sloopy I really have not delt with counting in php I have a prgrep script that will replace but i want to set up so it counts by 2 4 6 8 then i can fig it out but this has got me stumped thank you