learning_brain
New Member
- Messages
- 206
- Reaction score
- 1
- Points
- 0
I have searched around everywhere for the right way of doing this.....
I have an image search engine and as part of it, I have a page that can extract and store img sources.
The problem is that the regex I'm using is not always reliable.
1) issues with relative paths (doesn't inlcude complete path)
2) there is also an issue with links such as "LBPC-Style/site_icons/profile.png".
images are always a problem due to the construct.
i.e. <img src="http://www.mysite.com/image.png"/> would be ideal but...
<img alt="description" src="image.png" width="100"/> is not.... see what I mean?
Is there a better way of doing this?
I have an image search engine and as part of it, I have a page that can extract and store img sources.
The problem is that the regex I'm using is not always reliable.
1) issues with relative paths (doesn't inlcude complete path)
2) there is also an issue with links such as "LBPC-Style/site_icons/profile.png".
PHP:
<?php
//define url to search
$url = $_POST['url'];
//get contents
$contents = file_get_contents($url);
//set matching pattern for img tag source
$pattern = '/src=[\"\']?([^\"\']?.*(png|jpg|gif))[\"\']?/i';
//match all img tag source
preg_match_all($pattern, $contents, $images);
//count number of items in array
$imageCount = count($images[1]);
//loop through each item
for ($i=0; $i<$imageCount; $i++){
echo "<br/>".$images[1][$i];
echo '<img src="'.$images[1][$i].'" width="100"/>';
$insertSQL = sprintf("INSERT INTO IMAGES (URL, KEYWORDS) VALUES (%s, %s)",
GetSQLValueString($images[1][$i], "text"),
GetSQLValueString($images[1][$i], "text"));
$Result1 = mysql_query($insertSQL, $freewebhost) or die(mysql_error());
}
?>
images are always a problem due to the construct.
i.e. <img src="http://www.mysite.com/image.png"/> would be ideal but...
<img alt="description" src="image.png" width="100"/> is not.... see what I mean?
Is there a better way of doing this?