Help me in this

Discussion in 'PHP' started by balasun, Aug 5, 2008.

  1. #1
    Hello all,

    I need ur help in the below work.

    I have the variable in like $scname='CR270SL8 27'' TV"' ; which is fetched from DB. It changed dynamically like CR202SL8 20'' TV etc.

    I want to display the above variable values like CR270SL8 in first line and 27" TV in second line like

    CR270SL8
    27" TV
    It is the dynamic variable. Please help me if u know the ans..
     
    balasun, Aug 5, 2008 IP
  2. ahowell

    ahowell Peon

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If "CR270SL8" is the model/sku and will always be the first item in that field, you
    can:

    $scName = 'CR270SL8 27" TV';
    $scParts = explode(' ', $scName);
    
    $sku = array_shift($scParts);
    $desc = implode(' ', $scParts);
    
    echo "{$sku} <br /> {$desc}";
    PHP:
     
    ahowell, Aug 5, 2008 IP
  3. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #3
    $scname = $row['scname'];
    
    $a = explode(' ',$scname);
    
    $b = $a[0];  //<---------CR270SL8
    
    $c = $a[1].' '.$a[2];   //<--------27" TV
    PHP:
     
    php-lover, Aug 5, 2008 IP
  4. CarcaBot

    CarcaBot Active Member

    Messages:
    389
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #4
    CarcaBot, Aug 5, 2008 IP