Im currently trying to get PHP to look through a webpage and pick out a picture of choice. Basically I have coded for the search to look for the keyword, and if 'alt=' is within 40 characters of the key word that picture will be selected.
So in theory if IPOD is searched and is found within the document, alt= will then be searched for, and hopefully something like this will be output:
alt="Apple IPOD 20Gb"
For some reason my while loop seems to be endless, but im having trouble seeing why, heres the code:
if ($code)
{
$input = 'ipod';
$inputText= strpos($code, $input);
}
$topBoundary = $inputText - 600;
$topSectionLength = $inputText - $topBoundary;
$topSection = Substr($code, $topBoundary, $topSectionLength);
if ($topSection)
{
$alt = 'alt=';
$findAlt = strripos($topSection, $alt);
$findAlt = (600 - $findAlt);
$newInput = $inputText;
$newAlt = $findAlt;
while ($newAlt > 40)
{
$cutInput = $finishBody - $newInput;
$startNewInput = Substr($code, $newInput+1, $cutInput);
$newInput = strpos($startNewInput, $input);
echo 'This is the new input code';
echo $newInput;
$tempTopBoundary = $newInput - 600;
$tempTopSectionLength = $newInput - $tempTopBoundary;
$tempTopSection = Substr($code, $tempTopBoundary, $tempTopSectionLength);
$newAlt = strripos($tempTopSection, $alt);
$newAlt = (600 - $newAlt);
}
}
Any views grateful