2

I have a long xml string that I am getting the length of to do a comparison. On the Linux Environment, it gets a value of 2788, but on Windows Environment, it's getting 2860. I have diff'ed the output, and they appear to be the same string. I have also tried htmlentities for the debug and utf8_decode on the string before doing the comparison, but no change in result. Why is this disparity here?

var_dump($xml);
print_r($xml);
print_r(htmlentities($architype_xml));
echo strlen(utf8_decode($xml));
echo strlen($xml);

Also, I don't believe I see a difference in new lines, but perhaps var_dump and print_r isn't giving me the full picture, I'm unsure how else to check.

Goose
  • 4,764
  • 5
  • 45
  • 84
  • `they __appear__ to be the same string`... therein likely lies the problem.... Are there perhaps html entities in the string that might be interpreted by the browser, but interpreted by the back-end in the other? – Mark Baker Dec 08 '15 at 15:48
  • windows vs. linux new lines, windows takes 2 characters for a newline while linux takes one – Alex Andrei Dec 08 '15 at 15:49
  • @MarkBaker, already tested for that before, updated my answer. – Goose Dec 08 '15 at 15:51
  • Hex dump the two strings, and compare them byte-by-byte – Mark Baker Dec 08 '15 at 15:51
  • Also double-check the `php.ini` setting `mbstring.func_overload` on both servers, as this can change the behaviour of `strlen()` - http://php.net/manual/en/mbstring.overload.php - really, there's very little justification ever to have it set to anything other than 0 – Mark Baker Dec 08 '15 at 15:53
  • i suggest you normalize the line endings before working with the file, see here http://stackoverflow.com/questions/7836632/how-to-replace-different-newline-styles-in-php-the-smartest-way – Alex Andrei Dec 08 '15 at 15:56

1 Answers1

2

probable newline characters in windows being "\n\r" and only "\n" on linux?

can you give us the string ?

EDIT: To remove the EndOfLines

$xml = str_replace(PHP_EOL, '', $xml)
maazza
  • 7,016
  • 15
  • 63
  • 96
  • How would I accommodate for this in my code? It's private data, but it happens with several string, not just the one in my example. – Goose Dec 08 '15 at 15:52
  • 1
    remove newlines "\n" and "\r" characters – maazza Dec 08 '15 at 15:53
  • That's exactly correct. Upvote for now, but if you update your question with the solution of removing \n and \r characters, I'll mark it as a correct answer. I used `$xml = str_replace(PHP_EOL, '', $xml)` – Goose Dec 08 '15 at 16:28