Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP: int - char/string conversion and vice versa

  • 02-04-2002 2:20pm
    #1
    Registered Users, Registered Users 2 Posts: 14,149 ✭✭✭✭


    Hey guys,

    just wondering if anyone knows how to convert a string to int (or vice versa) in PHP. I can't seem to find anything in the manual (before someone utters the immortal acrynom :p)

    What I have is this:

    $today = getdate() ;
    $var1 = 2000 ; // start year
    $var2 = $var1++ ;
    $var3 = $today ; // current year (taken from system clock)

    ...
    ...
    ...

    echo $var1 ;
    while($var2 < $var3)
    {
    echo $var2
    $var2++ ;
    }
    echo $var3 ;

    basically what I'm trying to do is create an input field (<select>) which is self-updating as the years roll on so to speak.

    The problem is (best as I can make it) that $var3 isn't an integer and that's the stumbling block. So any suggestions would be greatly appreciated :)

    [edit]
    Where's C/C++'s itoa or atoi functions when you need them?!!! :ermm:
    [/edit]


Comments

  • Registered Users, Registered Users 2 Posts: 944 ✭✭✭nahdoic


    [PHP]<?php
    $today = getdate();
    $var1 = 2000 ; // start year
    $var2 = $var1++ ;
    $var3 = $today ; // current year (taken from system clock)


    echo $var1 ;
    while($var2 < $var3)
    {
    echo $var2 ;
    $var2++ ;
    }
    echo $var3 ;

    ?> [/PHP]


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    See the section on Type Casting on the Type Juggling page. Also see the intval() and related functions. In the manual. :)

    adam


  • Registered Users, Registered Users 2 Posts: 14,149 ✭✭✭✭Lemming


    Originally posted by dahamsta
    See the section on Type Casting on the Type Juggling page. Also see the intval() and related functions. In the manual. :)

    adam

    You, sir, are a legend!!! :D
    I'll even forgive your manual reference :p (I kinda suspected I was lookin in the wrong places mind you! :rolleyes: )


  • Registered Users, Registered Users 2 Posts: 944 ✭✭✭nahdoic


    Gonna stop trying to answer these programming questions. Never seem to understand what people want. Anyway here is another solution too.

    [php]<?php
    $today = getdate() ;
    $var1 = 2000 ; // start year
    $var2 = $today ; // current year (taken from system clock)
    for($i=$var1;$i<=$var2;$i++)
    echo $i;
    ?>
    [/php]


Advertisement