How do I conert a string to a number?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Winter
Forum Newbie
Posts: 15
Joined: Fri Feb 07, 2003 12:29 pm
Location: Texas
Contact:

How do I conert a string to a number?

Post by Winter »

hello..

Would you please tell me how do I convert a string to a number (integer)?

Thank you..


Winter :oops:
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

Code: Select all

<?php
$my_int = intval($my_var);
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

PHP is loosely typed so depending on what you are trying to do it's probably not neccessary to change the type of the variable.

Mac
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

unless there is a comma or somesuch in the varialbe, and you just want the numeric value of the contents of the variable =)
Post Reply