Script that reads formatting marks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #1

    Script that reads formatting marks

    Does anybody know of a test editor or a useful script that can view the 'invisible' formatting marks in a text file.

    Line breaks in particular cause me huge problems when csv and xml files are passed between different companies and systems, most certainy Unix and Windows.

    I would like to read the ASCII character that is actually there not what Microsft thinks is there.

    I know this is not really PHP, but I don't know where it belongs.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You mean like a hex editor?

    Comment

    • code green
      Recognized Expert Top Contributor
      • Mar 2007
      • 1726

      #3
      Yes, a hex editor would be alright.
      Do you know of one, or do I have write my own?

      Comment

      • HaLo2FrEeEk
        Contributor
        • Feb 2007
        • 404

        #4
        Probably write your own, I don't know of any, though I'm sure some exist. If you know exactly which formatting marks you want to look for you could simply str_replace those with their hex equivalent. If you want to be able to view all characters as their hex values, you could iterate through the string like this:

        Code:
        $str = "test";
        
        for($i = 0; $i < strlen($str); $i++) {
          echo str_pad(dechex(ord($str[$i])), 2, "0", STR_PAD_LEFT)." ";
          }
        This outputs:

        74 65 73 74

        The hex equivalent of the string "test".

        First you're getting the decimal (ASCII) value of the character, then you're getting the hex value from the decimal value, and just for safety, padding the string to a length of 2 with a "0" character, since, for example, a decimal value of 5 will display as 5 in PHP, but it's actual hex value is 05. The padding is just in case there are any characters whose decimal value is less than or equal to 16 (which is 0F in hex).

        Edit: Also, if you want, you can wrap that in strtoupper(). This isn't really necessary, since the hex byt 0f is the same as 0F, but it just adds a uniformity.

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          I use Hex Editor Neo. They have a free version that has a smaller feature set but is good enough for light use.

          Comment

          • code green
            Recognized Expert Top Contributor
            • Mar 2007
            • 1726

            #6
            Part of the probem is formatting marks that are missing,
            in particular carriage returns so str_replace doesn't help here.
            I need this mainly for debugging script generated files, such as CSV and XML that are being sent via FTP.
            I will have a look at Neo.
            Thanks for the suggestions

            Comment

            Working...