Hey guys,
I've been stuck on this for a while. I'm trying to make a few different PHP scripts to accomplish similar things. For the first one, I wanted to be able to take in a URL and extract a small piece of data from it. For example:
Code:
http://www.somewebsite.com/123456_1234567890123_1234567890_12345678_1234567_n.jpg
From this, I want to extract the "12345678" portion of this URL. It will always be the third to last fragment (separated by _) from the file extension. The fragments can be any length, the last one always being an "n". I have no idea where to start for this task.
For my second task, I'm trying to rip all the image tags out of some source code. I don't want to include the images if the source URL is from a specific website. I have some code working that rips all of the image tags from a site, but can't figure out how to make it not include ones from the "banned" site. Here's what I have:
PHP Code:
<?php
$url = "example.com";
$text = file_get_contents($url);
preg_match_all("/<img[^>]+\>/i", $text, $match);
print_r($match);
?>
So say I had a site called banned.com and didn't want to include in my search any image tags like <img src="banned.com/blahblah.jpg" />. Would RegExp's be the best choice for this? I've heard somewhere that it's not good for omitting search results.
Thanks in advance and happy holidays.
|