473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

sting to integer conversion

hi,

I'm struck in string conversion into integer,

if my $string1 is "(10+20)"
1. how to calculate the value of the string,
2. how to convert this string and string value into integer

and generally how to convert string intointeger...

kindly update asap.
thanks
Sep 2 '10 #1
1 1510
kovik
1,044 Expert 1GB
In order to get the value of a statement in a string, you could make use of the eval() function. Just be sure that you validate all input to ensure that no malicious code is executed.

As for the general conversion of strings to integers and vice versa, just use typecasting. PHP is a very loosely typed language, so variable types are flexible.

i.e.
Expand|Select|Wrap|Line Numbers
  1. $value = "10"; // currently a string
  2. $value = (int)$value; // now, it is an integer
  3. $value = (string)$value; // now, it is a string again
Sep 2 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: syntax | last post by:
hi i have a simple question. question1 ----------- i have a string char string = "114 145"; i simply want to extract two integers from it i.e i want 114 and 145 ..
30
by: priya | last post by:
Hi How to concatenate two integer Values. Example Program : #include "Port.h" #include "BinaryConversion.h" # include "iostream.h"
4
by: Ed Sutton | last post by:
Is there an easy conversion from a hex string, for example "0x1234" to an int? I have written my own many times in other languages, I was just wondering if there might be something already...
1
by: Altman | last post by:
I am trying to write a program to write to the com port. I have some sample code and it says to use the function hComm = CreateFile("COM2", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,...
21
by: Frederick Gotham | last post by:
I set about trying to find a portable way to set the value of UCHAR_MAX. At first, I thought the following would work: #define UCHAR_MAX ~( (unsigned char)0 ) However, it didn't work for me....
10
by: Mike S | last post by:
Does anyone know the logic behind why in VB.NET the result of a floating-point division ('/') is -rounded- on being converted to an integer type, such as with statements like Dim x As Integer =...
1
by: charles_gero | last post by:
Hi all, I had a question about the topics in the subject and posted to comp.std.c, but feel it may also be appropriate here. Please excuse this crosspost if it is in bad form. I have a...
7
by: somenath | last post by:
Hi All, I am trying to undestand "Type Conversions" from K&R book.I am not able to understand the bellow mentioned text "Conversion rules are more complicated when unsigned operands are...
3
Kelicula
by: Kelicula | last post by:
Is there a handy function to convert a decimal to a real number? I tried Data::Types and to_int() but I don't have the mod loaded on the server, and I don't have access to be able to do it. ...
6
by: dipanmodi | last post by:
i want to make program of : Read float, and convert this in to demoted integer without using int. It is by using the reverse the IEEE float format. If you have any sollution please give me.
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.