Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP: int - char/string conversion and vice versa

  • 02-04-2002 03:20PM
    #1
    Registered Users, Registered Users 2, Paid Member Posts: 14,174 ✭✭✭✭


    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, Paid Member Posts: 14,174 ✭✭✭✭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