Regex Question
Hey can you guys help me out with this code? Basically I want to check a site for part of a word and then echo out the entire word. So for example say I have:
$url = file_get_contents("http://www.google.com","r");
$pattern = '/ages/';
if (preg_match($pattern,$url))
{
echo "its here";
}
else
{
echo "not here";
}
?>```
I'm looking for the string "ages" and I then want to echo out the full word, which, in this case, would be images. It's easy enough to see if the string exists on the site, but I have no idea how to get the whole word. Do you guys have any ideas how to do this? Thanks
That's very… Stupid code. Anyway.
I agree, but it's simple which is why I gave it as an example…
Are you saying just to replace
markup$pattern = '/ages/';
to
markup$pattern = "/([a-zA-Z]*)ages/";
I'm not trying to just see if a word ending with 'ages' exists on the page (if i was I would just change the pattern to '/[a-z]*ages/i', which is basically what you had).
I want to first see if the string 'ages' exists on the page, and then if it does, store the whole word that the string belongs to into a variable.
If for some reason I'm still not clear about what I'm trying to do (or if I'm not getting what you're saying), post back and I'll try to explain it again.