Finding HTML with PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Finding HTML with PHP

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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'!");
}
Post Reply