dongxing8766 2017-03-07 16:23
浏览 66
已采纳

PHP /将数字作为字符串发布,intval无法将其转换为数字

I'm grabbing a number using jquery, from a piece of data in my html, as follows.

This is the html line.

echo "<p class = 'bold center remainingland' data-RemainingLandForFacilities = $RemainingLandForFacilities>Remaining Land For New Facilities : " . ($RemainingLandForFacilities) . "</p>";

I get the data using jquery with this...

var remainingland = $(this).closest('div').find('.remainingland').attr('data-RemainingLandForFacilities');

(after pressing a button, which is 'this'). This works correctly and an alert shows me the number.

I then post to my php script with the usual...

$.post('scripts/upgradefacility.php',
            {
                remainingland : remainingland

And I collect it with.

$RemainingLand = filter_input(INPUT_POST, 'remainingland', FILTER_SANITIZE_STRING);

At this point, I do have the number, but it's a string (as confirmed by gettype). But when I try to convert it to an integer with...

$RemainingLand = intval($RemainingLand);

I just get a blank. I should point out that I just copy/pasted all of this from previous variables which I'm passing, all of which come through correctly, so this is really odd. I can only assume that I've made some error that I can't spot or that I've been doing something wrong all along but I've somehow got away with it until now.

  • 写回答

1条回答 默认 最新

  • dongwende1984 2017-03-07 16:58
    关注

    Your problem isn't that intval() fails converting your data into an integer, your problem is you're returning it with exit().

    exit() takes one argument. If it's an integer, rather than printing it out, it uses it as an exit status code.

    More information on how exit() works can be found in the php documentation here:- http://php.net/manual/en/function.exit.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件