View Full Version : Get background images from a css and add to a database?
Does any one know how you can make a script which goes through a .css file, and it will insert all the background image URL's into a database?
Bojangles
04-04-2008, 10:46 AM
Not too sure but wouldn't you make it so your database is able to grab all the files?
The database dosn't get the files, its the script which does it.
The database is just a place to store data :P
I have a feeling the scritp will use file_get_contents :P
Bojangles
04-04-2008, 11:18 AM
The database dosn't get the files, its the script which does it.
The database is just a place to store data :P
I have a feeling the scritp will use file_get_contents :P
Yeah but it will only return the files in a string by using file_get_contents.
Try this
string file_get_contents ( string $filename [, int $flags [, resource $context [, int $offset [, int $maxlen ]]]] )
RYANNNNN
04-04-2008, 11:19 AM
Yep, you'd use file_get_contents and preg_match_all, although the problem is people can lay out their backgrounds differently ... and therefore it's going to be near impossible to get all of them.
Bojangles
04-04-2008, 11:27 AM
I'm not sure if this is correct or not to don't bash me but couldn't he just store them in a file CHMOD'd t 777 and use
($con = fsockopen(filewhateverhere); to fetch them?
Humm, iv never been good with these functions :P
All I have is:
<?php
$url = "http://www.habbo.co.uk/myhabbo/styles/assets.css";
$page = file_get_contents("$url");
$start = explode("background-image: url(", $page, 2);
$end = explode(");", $start[1], 2);
$sticker = trim($end[0]);
echo ("$sticker");
?>
Which gets the first one xD
Yep, you'd use file_get_contents and preg_match_all, although the problem is people can lay out their backgrounds differently ... and therefore it's going to be near impossible to get all of them.
because there backgrounds are added from a panel, the set out is all the same :)
RYANNNNN
04-04-2008, 02:03 PM
Humm, iv never been good with these functions :P
All I have is:
<?php
$url = "http://www.habbo.co.uk/myhabbo/styles/assets.css";
$page = file_get_contents("$url");
$start = explode("background-image: url(", $page, 2);
$end = explode(");", $start[1], 2);
$sticker = trim($end[0]);
echo ("$sticker");
?>
Which gets the first one xD
because there backgrounds are added from a panel, the set out is all the same :)
Okay, probably best to use preg_match_all and then since they're all the same you can use regex to find them ... although I'm not great with regex so I can't help you from now
Okay, probably best to use preg_match_all and then since they're all the same you can use regex to find them ... although I'm not great with regex so I can't help you from now
I have never used preg_match_all, looks like ill have to do some research :P
Bojangles
05-04-2008, 02:11 PM
Research is key :)
RYANNNNN
05-04-2008, 02:12 PM
It's simple, it's just the regex pattern thats tricky.
irc.freenode.net #regex
They'll help you out though
Agnostic Bear
05-04-2008, 02:27 PM
It's simple, it's just the regex pattern thats tricky.
irc.freenode.net #regex
They'll help you out though
/background-image: url\((.*?)\);/i should do it i think
Invent
05-04-2008, 02:36 PM
Something like this Jack?
http://79.64.224.188:1337/jack.php
Something like this Jack?
http://79.64.224.188:1337/jack.php
Damn! You beat me! My script was nearly ready it was just displaying them all wrong. Damn lol
Something like this Jack?
http://79.64.224.188:1337/jack.php
Exactly like that :)
Decode
05-04-2008, 04:07 PM
Exactly like that :)
<?php
$url = file_get_contents("http://www.habbo.co.uk/myhabbo/styles/assets.css");
$look4 = "/background-image: url\((.*?)\);/";
preg_match_all($look4, $url, $images);
$echo = implode('<br> ', $images[1]);
echo "$echo";
?>
That should work :)
EDIT: and if you want to display the number of images.
<?php
$url = file_get_contents("http://www.habbo.co.uk/myhabbo/styles/assets.css");
$look4 = "/background-image: url\((.*?)\);/";
preg_match_all($look4, $url, $images);
$echo = implode('<br> ', $images[1]);
echo "$echo";
echo "<hr>There are currently ";
$number = preg_match_all($look4, $url, $images);
echo "$number";
echo "images/backgrounds";
?>
EDIT AGAIN: if you want to view the images on the page:
<?php
$url = file_get_contents("http://www.habbo.co.uk/myhabbo/styles/assets.css");
$look4 = "/background-image: url\((.*?)\);/";
preg_match_all($look4, $url, $images);
$echo = implode('<br> ', $images[1]);
echo "$echo";
echo "<hr>There are currently ";
$number = preg_match_all($look4, $url, $images);
echo "$number";
echo " images/backgrounds";
echo "<hr>";
$tochange = "$echo";
$start = array("http", "gif", "png", "jpg");
$replace = array("<img src=http", "gif>", "png>", "jpg>");
$htmlimages = str_replace($start, $replace, $tochange);
echo "$htmlimages";
?>
<?php
$url = file_get_contents("http://www.habbo.co.uk/myhabbo/styles/assets.css");
$look4 = "/background-image: url\((.*?)\);/";
preg_match_all($look4, $url, $images);
$echo = implode('<br> ', $images[1]);
echo "$echo";
?>
That should work :)
EDIT: and if you want to display the number of images.
<?php
$url = file_get_contents("http://www.habbo.co.uk/myhabbo/styles/assets.css");
$look4 = "/background-image: url\((.*?)\);/";
preg_match_all($look4, $url, $images);
$echo = implode('<br> ', $images[1]);
echo "$echo";
echo "<hr>There are currently ";
$number = preg_match_all($look4, $url, $images);
echo "$number";
echo "images/backgrounds";
?>
EDIT AGAIN: if you want to view the images on the page:
<?php
$url = file_get_contents("http://www.habbo.co.uk/myhabbo/styles/assets.css");
$look4 = "/background-image: url\((.*?)\);/";
preg_match_all($look4, $url, $images);
$echo = implode('<br> ', $images[1]);
echo "$echo";
echo "<hr>There are currently ";
$number = preg_match_all($look4, $url, $images);
echo "$number";
echo " images/backgrounds";
echo "<hr>";
$tochange = "$echo";
$start = array("http", "gif", "png", "jpg");
$replace = array("<img src=http", "gif>", "png>", "jpg>");
$htmlimages = str_replace($start, $replace, $tochange);
echo "$htmlimages";
?>
Thank you.
Do you know how to:
1) Make it so that the image is saved into a local direcotry
2) Save the IMG name, it it gets rid of " http://img2.cdn1.habbo.com/c_images/stickers/" and just inserts filename.gif into a database?
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.