On Thu, Oct 27, 2011 at 15:25, Tedd Sperling <tedd.sperl...@gmail.com> wrote:
> Hi gang:
>
> I have a few questions -- this is my first one.
>
> Please review this link:
>
> http://webbytedd.com/cccc/perms/
>
> This page simply reads the contents of a file of the user's choice and 
> displays the file's data.
>
> My first question is with regard to reading a file ( fread() ):
>
> If the user picks the PDF file, the [1] First 20 bytes are: %PDF...
> If the user picks a JPG file, the [1] First 20 bytes are:  ...JFFIF...
> If the user picks a GIF file, the [1] First 20 bytes are:  GIF89a...
>
> Of course, the above is just reading/echoing the header for each of those 
> files.
>
> Likewise, if the user picks a TXT or CSS file, then [1] First 20 bytes echoed 
> are the first 20 characters of the file.
>
> However, if the user picks a HTML or PHP file, there are no [1] First 20 
> bytes echoed.
>
> BUT, the ord() and chr() of the bytes ARE indeed collected and can be echoed 
> as shown in statements [2] and [3].
>
> So, my question is specifically "Why is the data gathered in the variable 
> $content not echoed for the HTML and PHP files, but is for all other files?"
>
> Please review the code shown.

    No need to review the code.  The first hunch I had proved correct.
 PHP opens with a less-than (left carat, or 'less-than') symbol, as do
HTML tags.  As a result, the browser interprets both as tags and tries
to parse them.

    Viewing the source of that page upon selection of the PHP or HTML
options displays the code as expected.

    Resolution:  str_replace('<','&lt;',str_replace('>','&gt;',$data));

    Technically, only the less-than symbols need to be replaced, but
you may as well - as Charley Jordan says - Keep It Clean.

-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to