Forum Moderators: coopster
<html>
<head><title>SearchTestA1.html</title></head>
<body>
<div id="Title of Section 1(endTitle)">
<p>Paragraph 1 in section 1 searchTerm</p>
<p>Paragrpah 2 in section 1</p>
</div>
<div id="Title of Section 2(endTitle)">
<p>Paragraph 1 in section 2</p>
<p>Paragrpah 2 in section 2 searchTerm</p>
</div>
<form action="GetTitles.php" method="post">
<input type="text" value="searchTerm" name="searchTerm" />
<input type="submit"/>
</form>
</body>
</html>
Now here is the php code that attempts to extract the "Titles" (i.e., the id
attributes of the divisions) that will eventually be wrapped in a link:
<?php #GetTitles.php
$htmlDoc = file_get_contents("SearchTestA1.html");
$htmlDoc = htmlentities($htmlDoc);
$var1 = <see notes below...>;
$beginChunks = explode($var1, $htmlDoc); // an array in which each element begins with "id="
$endChunks = explode("(endTitle)", $htmlDoc); // an array in which each element begins with
// "(endTitle)"
$offset = 0; // an offset in necessary for the following functions
// so that the position of the elements aren't duplicated
// store the begining positions of the "Titles" in an array
for($i = 0; $i < count($beginChunks); $i++){
$titleBeginPos[$i] = strpos($htmlDoc, $beginChunks[$i], $offset);
$offset += 10;
}
$offset = 0; // reset the offset
// store the positions of the ends of the "Titles" in an array
for($i = 0; $i < count($endChunks); $i++){
$titleEndPos[$i] = strpos($htmlDoc, $endChunks[$i], $offset);
$offset += 10;
}
// store the titles in an array
for($i = 1; $i < count($beginChunks); $i++){
$titles[$i-1] = substr($htmlDoc, $titleBeginPos[$i] + 6, ($titleEndPos[$i] - $titleBeginPos[$i]) - 16) . "<br/>";
}
// print the titles
for($i = 0; $i < count($titles); $i++){
echo $titles[$i];
}
?> // I stop here b/c this is all the code needed to ask my question
________________________________________________________________________________________
QUESTION:
How come if $var1 = "<div id="; then the only thing printed is:
0
But when $var1 = "id="; then the following gets printed:
Title of Section 1
Title of Section 2
Many thanks! 8)
John
$var1 = '<div id=';
'<' (less than) becomes '<'