Page 1 of 1

Finding HTML with PHP

Posted: Sun Mar 05, 2006 6:14 pm
by JAB Creations
I need to use PHP to find "<!--stuff-->" and let me know if it finds it. Otherwise I don't want the script to do anything. This script is a guess...but it gives me false positives; that means if the comment is not in the file (as is the case with my example below) it still says it found the comment.

Code: Select all

<html><head></head><body>
<?php
$fh = fopen('test.php', "rb");
$file = fread($fh, filesize('test.php'));
fclose($fh);
if(strpos($file, "<!--stuff-->")!== false)
{echo "string found";}
else
{echo "string not found";}
?></body></html>
Sorry to post this twice but the first thread pretty much became ignored because while people had good intentions it K-Oed the topic and I never got anywhere close to an answer! Please don't post if you have no clue how to approach this; thanks!

John

Posted: Sun Mar 05, 2006 6:56 pm
by Chris Corbyn

Code: Select all

$string = file_get_contents($file);

if (false === strpos($string, '<-- stuff -->')) //Remember it might return zero!
{
    die("I don't see you foo'!");
}