|
Posted by Julien CROUZET on 10/11/04 11:39
julian_m a exprimé avec précision :
> file AddHTML.htm:
> ----------------------------
> This line is <b>ok</b><br>
> This line is <b>ok</b><br>
> This line is <b>ok</b><br>
> <?PHP echo "This one has code prohibited "; ?>
> This line is <b>ok</b><br>
> This line is <b>ok</b><br>
> ----------------------------
>
>
> file index.php
> ------------
> <html><head .... all you know here
>
> <?PHP
> function p_function_AddOnlyHTML($AL_file)
> {
> $handle = fopen($AL_file, "r");
> while (!feof($handle)) {
> $buffer = fgets($handle, 4096);
> //if (strpos($buffer, '<?') === true){
> if (strpos($buffer, '<?') === true){
> echo "El archivo contiene código PHP<br>";
> return false;
> }
>
> echo $buffer;
> }
> fclose($handle);
> }
>
>
> p_function_AddOnlyHTML("AddHTML.htm");
>
> ?>
>
>
> It actually prints
>
> This line is ok
> This line is ok
> This line is ok
> This line is ok
> This line is ok
>
> whereas I would expect
>
> This line is ok
> This line is ok
> This line is ok
>
> beacause, after 3rds line, function p_function_AddOnlyHTML should find
> a '<?' occurrence
>
> Any hints? I'm really lost...
>
The probleme is here if : (strpos($buffer, '<?') === true){
strpos returns the position of the first occurence of your searched
string or FALSE if it doesn't find it.
The operator === is a STRICT comparison, that means that it'll be true
if the operands are EXACTLY the same.
As your strpos finds a '<?', it returns its position in your file,
(ie: 45), and 45 is not EXACTLY true.
You have to change
strpos($buffer, '<?') === true){
for
strpos($buffer, '<?') !== false){
Greetings,
--
Julien CROUZET - DSI Theoconcept
julien.crouzet@/enlever ca\theoconcept.com
http://www.theoconcept.com
Navigation:
[Reply to this message]
|