?
Solved

String to Integer issue in php

Posted on 2011-02-23
5
Medium Priority
?
333 Views
Last Modified: 2012-05-11
Hi
I'm having trouble with retrieving a couple variables appended to a url and dividing them and assigning the result to a new variable. I suspect it has something to do with them possibly being strings as opposed to integers so the math is returning 0 for a value. But I could be absolutely wrong.

Below is the pertinent code.

When dividing expenses by income the value for $tdsr keeps appearing as '0'

Any ideas?
<?php
header("content-type: text/xml");
echo  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

$recording = $_REQUEST['recording'];
$numbertocall = $_REQUEST['numbertocall'];
$income = $_REQUEST['income'];
$expenses = $_REQUEST['expenses'];

$tdsr = $expenses/$income;


?>

Open in new window

0
Comment
Question by:tjyoung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 14

Accepted Solution

by:
brendanmeyer earned 2000 total points
ID: 34966694
have a look at http://www.php.net/manual/en/function.intval.php


$income = intval ($_REQUEST['income']);
$expenses = intval ($_REQUEST['expenses']);
0
 
LVL 1

Author Comment

by:tjyoung
ID: 34966727
Hi, I did try that but I suspect my implementation must be wrong. Below is a more comprehensive view of the code I'm using with intval in.

Do you see what I'm doing wrong? It may be something very newbie...

Its mixed in with some Twilio code. All works except the value of $tdsr is '0'.
<?php
header("content-type: text/xml");
echo  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

$recording = $_REQUEST['recording'];
$numbertocall = $_REQUEST['numbertocall'];
$income = intval($_REQUEST['income']);
$expenses = intval($_REQUEST['expenses']);

$tdsr = $expenses/$income;


?>

<Response>

<?php
if ($_REQUEST['Digits']=="1"){

	$approvalID = mt_rand(301, 9950);
	$approvalSlow = wordwrap($approvalID,1,",",TRUE);


	if ($tdsr >= 70) { ?>
		<Say>This is hopeless</Say>
	
	<?php } elseif ($tdsr >= 60 && $tdsr < 70) { ?>
		<Say>You're application requires a few additional questions to be pre-approved</Say>
		<Say>Our Dealership will contact you so we can gather some additional information to get your application approved.</Say>
	
	<?php } elseif ($tdsr < 60) {?>
		<Say> Congratulations, you are Pre-Approved!</Say>
		<Say> Your Approval ID is <?php echo $approvalSlow ?></Say>
		<Say> Please make a note of your Pre-Approval ID </Say>
		<Say> That number again is <?php echo $approvalSlow ?></Say>
		<Say> Your total debt service ratio is <?php echo $tdsr ?></Say>
	<?php
	
	$email = "email@email.com";
	$subject = "New 5 Second Phone Credit App! Approval ID: ". $approvalID;
	$body .= "The Caller's recorded name is:";
	$body .= $_REQUEST['recording'].".mp3\n\n";
	$body .= "The Caller's reverse lookup name if available was: ${_REQUEST['CallerName']}\n\n";
	$body .= "The Caller's preferred phone number is: ${_REQUEST['numbertocall']}\n\n";
	$body .= "The Caller's display phone number is: ${_REQUEST['From']}\n\n";
	$body .= "The Caller is in: ${_REQUEST['CallerCity']}\n\n";
	$body .= "The Caller's TDSR: ". $tdsr."\n\n";

    
	$headers = 'From: me@me.com' . "\r\n";
	$headers .= 'Reply-To: me@me.com' . "\r\n";
	$headers .= 'X-Mailer: Twilio';

	mail ($email, $subject, $body, $headers);
	}
	?>

Open in new window

0
 
LVL 1

Author Closing Comment

by:tjyoung
ID: 34966745
Your answer was correct. I was implementing it incorrectly initially.
thanks!
0
 
LVL 6

Expert Comment

by:MatthewP
ID: 34966760
I can't see what's wrong with that and you shouldn't even need intval. Have you checked the raw values as they come into the script before you've touched them?

Just add

var_dump($_REQUEST);

to the top of your script for a quick way to check this out.
0
 
LVL 1

Author Comment

by:tjyoung
ID: 34966780
Thanks. That was my issue. I marked your answer as correct simply because had I actually had the 'correct problem' your response was right.
var_dump is good to know as well.

Thanks again.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question