Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-13-2004, 10:05 AM   PM User | #1
oztinks
New Coder

 
Join Date: Sep 2002
Location: Australia
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
oztinks is an unknown quantity at this point
looping arrays

Hi,
I have my script returning this from a form
body { line-height: normal;
color: transparent;
font-weight: normal;
font-style: normal;
text-decoration: none;
text-align: left;
background-color: transparent;
}

but I need to ignore $v2 and $v3 if $v3 is normal or transparent making it return
body {
font-size: 12px ;
color: black;
text-decoration: none;
text-align: left;
background-color: white;
}
I have tried
if (!empty($v3)||( $v3 != 'normal'))
but then the !empty dosen't work



PHP Code:
<?php function makecss(){
            global 
$style;
                foreach (
$style as $key => $value) {
                echo 
"$key {";
                    foreach (
$value as $v2 => $v3) {
                    if (!empty(
$v3)){
               echo 
"  $v2:  $v3; \n ";}
    }
                echo 
"}\n";
}
}
makecss()
?>
__________________
The problem is IE
oztinks is offline   Reply With Quote
Old 05-13-2004, 05:32 PM   PM User | #2
cpradio
New Coder

 
Join Date: May 2003
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
cpradio is an unknown quantity at this point
Personally, I would use:
PHP Code:
trim($v3) != "" 
__________________
cpCommerce - Finally a template based open-source e-commerce solution
cpradio is offline   Reply With Quote
Old 05-14-2004, 12:42 AM   PM User | #3
oztinks
New Coder

 
Join Date: Sep 2002
Location: Australia
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
oztinks is an unknown quantity at this point
Thanks cpradio,
but I can't get the trim function to return the right results.
I ended up nesting a few if statments to filter the result seems a bit long winded but it is working

PHP Code:
<?php 
$style 
= array('body' => array('color'=> 'black','width'=>'100px','font-family'=>'verdana'),
                
'div' => array('color'=> '''font-size'=>'normal','font-family'=>'arial'),
                
'.small'=>array('color'=> 'transparent','font-size'=>'8px','text-align'=>'left'));
function 
makecss(){
            global 
$style;
                foreach (
$style as $key => $value) {
                echo 
"$key {\n";
                    foreach (
$value as $v2 => $v3) {
                    if (
$v3 != 'normal'){
                     if (
$v3 != 'transparent'){
                      if (
$v3 != 'left'){
                      if (!empty(
$v3)){
               echo 
"$v2:  $v3; \n ";
               }
               }
               }
               }
    }
                echo 
"}\n";
}
}
makecss() 
?>
__________________
The problem is IE
oztinks is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:39 PM.


Advertisement
Log in to turn off these ads.