I'm trying to find the position of the HTML element in a HTML document. So i do this:
$filestring = file_get_contents($filename); //get the raw file
$filestring = htmlspecialchars($filestring);
$pos = strpos($filestring, "<head>"); //find the position of <head>
print_r($pos); //print the position
End print_r don't show nothing. I think it is due to the special characters, but do not understand how to do.
There is no such things as <head>
in $filestring. When you use htmlspecialchars, the <
and >
get replaced:
http://php.net/manual/en/function.htmlspecialchars.php
$pos = strpos($filestring, "<head>");
Or don't use htmlspecialchars when searching for the string
Why do you use htmlspecialchars
? Do you understand that using this function causes all entities like >
or <
to be replaces by their representations like >
or <
?
So, the solutions are
htmlspecialchars
<head>
but for <head>
i think you should remove this line from your code.
$filestring = htmlspecialchars($filestring);