Hi,
For a challenge i decided to make a 'poot'-like site that takes the content of a web page and does something crazy to the content. I've almost got it working properly. For some reason, it is only changing some of the text on the page when i want it to change all the text.
Here's what i'm doing. I load the target url into a variable, then lop off the <head> and store it in another variable. I then explode the remaining body section using the whitespace separator.
The result is an array of 'words', some of which may be bits of tags and some will be visual content. I wrote the following loop to determine what is outside tags and change only stuff that isn't part of a tag:
foreach ($alltext as $word) {
if (substr_count($word,'<')!=0) {
// Its a start of a tag
$tag = 1;
} elseif (substr_count($word,'>')!=0) {
// Its the end of a tag
$tag = 0;
} elseif ($tag == 0) {
// Only make change if tag is 0
if (strlen($word)>2) {
$chars = strlen($word)-3;
$word = 'mi';
while ($chars != 0) {
$word .= 'a';
$chars = $chars - 1;
}
$word .= 'ow';
}
}
$html .= $word.' ';
} // end foreach
I have the suspicion that the problem lies in the fact that not all 'words' are separated by whitespace, but could in fact be separated by a newline or tag. When i use explode to create the array of words not each is properly separated. I don't know how to take this into account.
Anyway i hope someone will be able to make sense of why some words are being replaced and some not. For an example of what I mean, check this out:
http://www.littlink.com/catify/?url=http://www.yahoo.com
All words should be "miaow", but instead only some are changed.
Thanks in advance,
Don