Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Old 02-10-2004, 03:46 PM Is this possible?
Tyran37's Avatar
Novice Talker

Posts: 8
Trades: 0
Hi, I wonder if it is possible to have php convert a string to an integer by calculating its value.
Here's what I mean:
(int)"9*8+5"
becomes 9
(php uses the first int in the string)
Is it possible to have this string calculated, so I would get 77?
Tyran37 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-10-2004, 10:48 PM
Webmaster Talker

Posts: 589
Trades: 0
Huh I cant think of a way to do this now but I will get back to you after I ponder this one.
thevirus is offline
Reply With Quote
View Public Profile
 
Old 02-11-2004, 12:20 AM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
I think I understand you, you want PHP to do the math instead of thinking 'OK, this is a string.', correct? In that case, you can just eval it as a mathematical equation:

PHP Code:
$math_string "9*8+5";
eval(
'$myvar = '$math_string ';'); // notice how you don't add quotes around the math_Stirng variable, this way PHP evaluates it as numbers 
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 02-14-2004, 11:21 AM
Tyran37's Avatar
Novice Talker

Posts: 8
Trades: 0
Yes, that's what I meant! (sorry for my crappy explanation but my english isnt too good )
But at least someone understood me :-)
Thanks a lot!
Tyran37 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Is this possible?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12886 seconds with 12 queries