I apologize right out of the gate if this is the wrong forum… typical excuse, I’m new here.
If anyone can help with this, I’ll be so thankful! I’ve wrestled with this longer than I care to mention, and Google is probably eyeing me for so much bandwidth usage from searching for what I am sure should be a simple task in PHP!
Objective: Creating a PHP function that reads a remote HTML file, explodes it into an array of HTML strings based on newlines, finds the key from said array of strings that contains a particular phrase, then returns the key number into a variable – so I can then explode that particular string, strip the HTML tags, and return only the portion of that string I want to then display with my script.
I have accomplished reading the remote file, exploding into an array of strings based on newlines, manually finding the correct array key, exploding the string, stripping the tags, and returning the portion of the string I want.
What I can’t seem to figure out is how to make my function search through the array of strings, find a particular phrase in one of those strings (not the full string, obviously), and return the key for that string.
Example: I have an array thus:
0 => I have a cat.
1 => My dog is blue.
2 => One cute hamster.
How in the world can I take that array, search it for “dog” and have PHP return “1” so I can assign that key number to a variable?
I have tried a plethora of approaches including in_array, array_search, and foreach key/value loops followed with in_array, array_search, etc with no success. Any input would be mucho appreciated-o.