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 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题