Reputation: 693
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.
Upvotes: 1
Views: 453
Reputation: 957
i think you should remove this line from your code.
$filestring = htmlspecialchars($filestring);
Upvotes: 0
Reputation: 1045
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
Upvotes: 3
Reputation: 54841
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>
Upvotes: 3