4

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.

2
  • 4
    Well, string(2386) " booking|1||4000015|23628 ", That means the string has 2386 bytes. You should look the view-source of your test page, instead of the rendered html which is obviously hiding most of the string. Commented Dec 20, 2012 at 17:51
  • @Esailija maybe xdebug settings? Does standard php.ini let you control the behavior of var_dump at all? Commented Dec 20, 2012 at 17:54

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

ya that worked perfect thanks; turns out there was a hidden input element and one of the values had a pipe (|) in it that was being caught on the explode
1

To see the result of the function var_dump() literally, use HTML's pre element:

 echo '<pre>'; var_dump( $bookingResults ); echo '</pre>'; 

Comments

0

use print_r() with pre tags instead of var_dump()

echo '<pre>'; print_r( $bookingResults ); echo '</pre>'; 

Hope it helps

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.