Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Member Arkantos's Avatar
    Join Date
    Jul 2005
    Posts
    66
    Member #
    10732
    hello,

    i am learning PHP. so you may mark me as a newbie.:classic:

    now, i have struck a problem.

    the problem:
    HTML Code:
    <?
    $fp = fopen("counter.txt", "r");
    $count = fread($fp, 1024);
    fclose($fp);
    ?>
    now $count is a number. as in numeric variable.
    suppose it contains the value of 14
    now i want to convert / normalise the number to a 'n' charecter alphanumeric variable.

    so NUMBER '14' becomes
    '000000014' - 9 character WORD.

    similarly 73847 becomes 000073847

    i have come to the conclusion that only one command will not do this. so there needs to be a set of commands. am i right??

    i donot want the complete solution, i want to solve this myself.
    a few tips, a few commands, the code flow will definitely point me in the right direction. in short a nudge.

    can you point me in the right direction??

    thank you in advance,
    Arkantos.
    No bastard ever won a war by dying for his country, he won it by making the other poor dumb bastard dying for his country.
    General George S. Patton (US Army)

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Hey.

    So you want the string to be 9 characters long, with the last characters being the numerical variable?

    You could get the length of the numerical variable, and then set another variable to 9 - the length, then say you have 3 left.

    So the numerical var is 6 in length, we need to give it 3 padding 0's

    You could use a loop, 0 to remainder, and add (.=) a 0, then once outside the loop, add the string that contains the padding 0's and then the numerical variable.

    Good luck

  4. #3
    Member Arkantos's Avatar
    Join Date
    Jul 2005
    Posts
    66
    Member #
    10732
    oh man, i am so stoopid

    i kept thinking of GWBASIC variables, and thought num and alphanum vars werent transmutable.

    honest, i went through the ENTIRE official manual, before i posted.

    $norma = "00".$count;
    this line helped check your line of reasoning. it worked.
    now i just have to find the command to find the length of the num variable.


    many many thanx, bfsog.
    Arkantos!
    No bastard ever won a war by dying for his country, he won it by making the other poor dumb bastard dying for his country.
    General George S. Patton (US Army)

  5. #4
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    I'm not a php expert, so I'm not sure, but I believe there are no explicit datatype definitions.

    However, I think you can do it in one line with something like this:
    PHP Code:
    $output substr('000000000'strlen($longint)) . $longint

  6. #5
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Internally, PHP does use strict types (you can get the type of any variable), but it doesn't give a damn in your actual code: both a blessing and a mighty fierce curse.

    If you've used C, then you're probably aware of [phpfunction]sprintf[/phpfunction] which is much cleaner, at least in implementation. It's hideous to look at, though.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  7. #6
    Member Arkantos's Avatar
    Join Date
    Jul 2005
    Posts
    66
    Member #
    10732
    @transio and @ filburt1, thank you for the answers. it helps.

    i havent used c. i only know basic to a limited extent. i used to develop robotic arms and programmed them in basic.
    php is a whole new cup of tea.

    this sprintf cum substr should help.

    i thank all you three for the help given.

    in gratitude,
    Arkantos.

    ps: i just wanna know, how do you say, the request has been filled?? there is supposed to be button or a tick box.......
    No bastard ever won a war by dying for his country, he won it by making the other poor dumb bastard dying for his country.
    General George S. Patton (US Army)

  8. #7
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Edit the first post and put [Solved] at the beginning of the thread title.

  9. #8
    Member Arkantos's Avatar
    Join Date
    Jul 2005
    Posts
    66
    Member #
    10732
    many many thanks.

    Arkantos.
    No bastard ever won a war by dying for his country, he won it by making the other poor dumb bastard dying for his country.
    General George S. Patton (US Army)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:07 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com