Jump to content

editting css file...


ToonMariner

Recommended Posts

Hi peeps,

OK i have a series of statements in a css file like so
[code]
#nav li#navintroduction a
{
background: transparent url(../images/nav/red.gif) no-repeat 0 0;
}

#nav li#navproducts a
{
background: transparent url(../images/nav/lightblue.gif) no-repeat 0 0;
}

#nav li#navbargain_selection a
{
background: transparent url(../images/nav/orange.gif) no-repeat 0 0;
}

#nav li#navspecials a
{
background: transparent url(../images/nav/brown.gif) no-repeat 0 0;
}

#nav li#navcontact a
{
background: transparent url(../images/nav/purple.gif) no-repeat 0 0;
}
[/code]

WITH THE NEW LINES

What I need to do is alter the image name (just the first part) based on id of the li element.

This is what I am trying but no joy as yet (i think i am pretty close though ;))

[code]<?php
$str = "#nav li#navintroduction a
{
background: transparent url(../images/nav/red.gif) no-repeat 0 0;
}

#nav li#navproducts a
{
background: transparent url(../images/nav/lightblue.gif) no-repeat 0 0;
}

#nav li#navbargain_selection a
{
background: transparent url(../images/nav/orange.gif) no-repeat 0 0;
}

#nav li#navspecials a
{
background: transparent url(../images/nav/brown.gif) no-repeat 0 0;
}

#nav li#navcontact a
{
background: transparent url(../images/nav/purple.gif) no-repeat 0 0;
}";

$styles = array (
1 => 'red' ,
2 => 'lightblue' ,
3 => 'orange' ,
4 => 'brown' ,
5 => 'purple'
);
$newsty = 4;

$id = 'products';

$filestr = preg_replace('/li#nav' . $new . ' a(.*)\/nav\/(.*)\.gif/s','li#nav' . $new . ' a$1/nav/' . $styles[$newsty] . '.gif',$str);
?>[/code]

So basically I just want to change the initial part of the file name BUT I think preg_replace is greedy (is it?) so i am not getting anything lie what i expect.

Hopefully from the code you will be able to see what I am trying to do, and even more hopefully point me in teh right direction.

Cheers people.
Link to comment
Share on other sites

Sorry. a typo shoudl be $id.

So the regex is...[code]
<?php
$filestr = preg_replace('/li#nav' . $id . ' a(.*)\/nav\/(.*)\.gif/s','li#nav' . $id . ' a$1/nav/' . $styles[$newsty] . '.gif',$str);
?>
[/code]

(this is going into a function so $id will chage)

so With[code]<?php
<?php
$str = "#nav li#navintroduction a
{
background: transparent url(../images/nav/red.gif) no-repeat 0 0;
}

#nav li#navproducts a
{
background: transparent url(../images/nav/lightblue.gif) no-repeat 0 0;
}

#nav li#navbargain_selection a
{
background: transparent url(../images/nav/orange.gif) no-repeat 0 0;
}

#nav li#navspecials a
{
background: transparent url(../images/nav/brown.gif) no-repeat 0 0;
}

#nav li#navcontact a
{
background: transparent url(../images/nav/purple.gif) no-repeat 0 0;
}";

$styles = array (
1 => 'red' ,
2 => 'lightblue' ,
3 => 'orange' ,
4 => 'brown' ,
5 => 'purple'
);
$newsty = 4;

$id = 'products';

$filestr = preg_replace('/li#nav' . $id . ' a(.*)\/nav\/(.*)\.gif/s','li#nav' . $id . ' a$1/nav/' . $styles[$newsty] . '.gif',$str);
?>[/code]

So with $id = "products" and $newsty = 4 I would like get

#nav li#navintroduction a
{
background: transparent url(../images/nav/red.gif) no-repeat 0 0;
}

#nav li#navproducts a
{
background: transparent url(../images/nav/[color=blue]brown[/color].gif) no-repeat 0 0;
}

#nav li#navbargain_selection a
{
background: transparent url(../images/nav/orange.gif) no-repeat 0 0;
}

#nav li#navspecials a
{
background: transparent url(../images/nav/brown.gif) no-repeat 0 0;
}

#nav li#navcontact a
{
background: transparent url(../images/nav/purple.gif) no-repeat 0 0;
}
Link to comment
Share on other sites

I think I need to do a negative lookahead, something like..[code]filestr = preg_replace('/li#nav' . $id . ' a(.*)\/nav\/(?!(\.gif))\.gif/s','li#nav' . $id . ' a$1/nav/' . $styles[$newsty] . '.gif',$str);[/code]

But how do I get that negative lookahead to include linebreaks?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.