On Sunday 25 April 2004 01:00 pm, David T-G wrote:
> Hi, all --
>
> I must be having a brain fart as well as going blind because I can't find
> in the manual how to do this.
>
> Given a string like #AABBCC or #112233 how do I get the
>
> 2nd-3rd
> 4th-5th
> 6th-7th
>
> position substrings so
Richard, et al --
...and then Richard Harb said...
%
% $color = '#aabbcc';
%
% if (strlen($color) == 7) {
%echo ' r: ' . substr($color, 1, 2);
[snip]
D'oh! I knew it should be substr but I could never find it! I was up to
page 1098 or such and muddling through all of the PCRE doc when I g
$color = '#aabbcc';
if (strlen($color) == 7) {
echo ' r: ' . substr($color, 1, 2);
echo ' g: ' . substr($color, 3, 2);
echo ' b: ' . substr($color, 5, 2);
} elseif (strlen($color) == 4) {
echo ' r: ' . str_repeat(substr($color, 1, 1), 2);
echo ' g: ' . str_repeat(substr($color, 2, 1
3 matches
Mail list logo