473,395 Members | 1,762 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,395 software developers and data experts.

add up an integer with the result from substr()

Hi,

I'm trying to add up an integer with the result from substr() like

$second_int = substr( .... ) + $int;

I know the result from substr() is an integer and so is $int but in the end
$second_int only has the result from the substr() and hasn't add up the
$int. What am I doing wrong in here... tried quite a few things but well....

Thanks in advance, Maarten
Jul 17 '05 #1
5 3030
MuffinMan wrote:
I'm trying to add up an integer with the result from substr() like

$second_int = substr( .... ) + $int;
Lookss good.
I know the result from substr() is an integer and so is $int but in the end
$second_int only has the result from the substr() and hasn't add up the
$int. What am I doing wrong in here...
No idea ...
tried quite a few things but well....


why don't you post what you tried?


$ cat xx.php
<?php
$int = 17;
$text = '01234';

$y = array();
$y[] = substr($text, 1, 2) + $int;
$y[] = substr($text, 1) + $int;
$y[] = substr($text, 1, 55) + $int;
$y[] = substr($text, 1, -2) + $int;
$y[] = substr($text, 1, -22) + $int;
$y[] = substr($text, -3, 2) + $int;
$y[] = substr($text, -3) + $int;
$y[] = substr($text, -3, 55) + $int;
$y[] = substr($text, -3, -2) + $int;
$y[] = substr($text, -3, -22) + $int;

print_r($y);
?>

$ php xx.php
Array
(
[0] => 29
[1] => 1251
[2] => 1251
[3] => 29
[4] => 17
[5] => 40
[6] => 251
[7] => 251
[8] => 19
[9] => 17
)

$
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2
> $second_int = substr( .... ) + $int;

$second_int = intval(substr( .... )) + $int;
should work imho.
http://fr2.php.net/manual/en/function.intval.php
Jul 17 '05 #3
| why don't you post what you tried?
Well, you're right nothing wrong in it but vars were defined outside a
function which gave a problem... next problem.... next thread..

Maarten
Jul 17 '05 #4
MuffinMan wrote:
Well, you're right nothing wrong in it but vars were defined outside a
function which gave a problem... next problem.... next thread..


You didn't make them global now, did you? :-)

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #5

| You didn't make them global now, did you? :-)

I didn't make them global tried to but failed.... Now it's ok.

Maarten
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andrew | last post by:
Hi I have a question is there a function in C++ to convert an integer into a Binary number Thanks in Advance Cheers
3
by: news.hku.hk | last post by:
could you tell me how can i convet a string to integer?? #include <iostream> #include <string> using namespace std; int main(){ int integer; string buffer("123456789");
9
by: Henrik | last post by:
In Java you can write something like this. Does anyone know how to do this in javascript? "byte b=Integer.parseInt(int value or String).byteValue;"
2
by: lawpoop | last post by:
Hey folks - I'm working on a spellchecking routine. The pspell libraries don't handle punctuation; I have to make a script a little smarter. I'm having a problem popping English posessive...
2
by: lizayica | last post by:
How to convert a string like '2,3,4' to three integer 2,3,4 in SQL procedure of DB2 UDB 8.2? Thanks!
5
by: Bob Stearns | last post by:
I have a table t1(id, other stuff) with 4 dependent (unrelated) tables ta(id, date, other stuff a), tb(id, date, other stuff b), tc(id, date, other stuff c), td(id, date, other stuff d). Any or all...
25
by: Tom | last post by:
I need to convert an integer to a unique code string consisting only of capital letters and numbers. I also need to be able to convert it back to an integer again. Example: 10 =DFG56JKG4 =10...
20
by: ML | last post by:
Integers are stored in tables using only 4 bytes. Is there a way in SQL to retrieve the value as it is actually stored, not converted back into the displayed number? For example, if I have...
11
by: panther | last post by:
Hi, I need to read part of an integer by another variable. As example, if user enter 761120921, then, i = 761120921 j = 76 k = 112 l = 0921 as that. can you explain how do i acheive this?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.