drf65218 2012-12-20 17:46
浏览 215
已采纳

var_dump()字符串和变量没有显示所需的结果

I am working on a script that curls another site and then parses the results. I seem to be having some weird problems and I can't understand where they are coming from; I have included the problematic part of my code as well as the output that is returned from it below:

<?php
    //my code to do some logic and build the curl

    $BookingConfirmation = curl_exec($ch);

    $testString = 'a test';
    var_dump($testString);
    echo '<br />';
    echo $BookingConfirmation;
    echo '<br />';
    var_dump($BookingConfirmation);
    echo '<br />';

    $bookingResults = explode('|', $BookingConfirmation);

    var_dump($bookingResults);
    die();
?>

when I then load the page, I am getting this output:

string(6) "a test"
booking|1||4000015|23628
string(2386) " booking|1||4000015|23628 "
array(6) { 
    [0]=> string(766) " string(1526) "108^1"> booking" 
    [2]=> string(1) "1" 
    [3]=>     string(0) "" 
    [4]=> string(7) "4000015" 
    [5]=> string(81) "23628 " 
} 

So according to what $BookingConfirmation is showing me, I wouldn't expect the array to contain "108^1" anywhere within it. Also, why would the var_dump of $BookingConfirmation be showing that it is a 2386 character string? It is nowhere near that long. Another question is, what is happening with the second element that should be in the array? ($bookingResults[1]) The final dump of that array is showing that there are 6 elements, but with #1 being skipped there are only 5 being shown.

It also might be useful to note that none of these variable names are used anywhere else in the code.

Any thoughts would be greatly appreciated.

  • 写回答

3条回答 默认 最新

  • doubi1713 2012-12-20 17:54
    关注

    Either use view-source, text/plain content-type, or run it through command line.

    <?php
        header("Content-Type: text/plain; charset=utf-8");
        //my code to do some logic and build the curl
    
        $BookingConfirmation = curl_exec($ch);
    
        $testString = 'a test';
        var_dump($testString);
        echo '<br />';
        echo $BookingConfirmation;
        echo '<br />';
        var_dump($BookingConfirmation);
        echo '<br />';
    
        $bookingResults = explode('|', $BookingConfirmation);
    
        var_dump($bookingResults);
        die();
    ?>
    

    I suspect the input contained <, which is rendered as some hidden html tag. I mean,string(2386) " booking|1||4000015|23628 ", means the string has 2386 bytes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决