Forum Moderators: coopster
What would the best and simplest way to do this?
I would also then want to remove any duplicates?
I.e. I want a variable, most probably an array that contains all the colours used in a html page, from which I have already retrieved the source for.
Pete
But to answer your question, a regular expression is probably your best bet.
Assuming your using PHP, it could look something like..
$matches = array();
preg_match_all( '/#[0-9A-F]{6}/im', $RetrievedInfo, $matches );
print_r( $matches );
That should match all 6 figure hex digits in RetrievedInfo that start with a hash symbol.
preg_match_all("¦(#[0-9A-F]+)¦i",$string,$matches);
$matches[0] should be an array of all the colours used.
$colors = $matches[0];
foreach ($colors as $color) {
print "$color<P>";
}
Should get you started. If you get any bugs use print_r($matches) - to get the full data structure.
[edit - beaten to it again.... ;) anyways nice to get two of the same answer!]
I had thought about the CSS issue and am still thinking about it. I can open a URL web page but the ways in which a CSS are specified can vary.
If it is included in <style></style> then my script will pick the colour out.
But the colour can be specified as a rel. link
<link rel="stylesheet" href="/css/default.css" type="text/css" />
or a direct link
<link rel="stylesheet" href="http://www.si.com/css/default.css" type="text/css" />
How do I open both of these types?
Pete