1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

replace {variable} with $variable

Discussion in 'PHP' started by dracula51, Nov 21, 2009.

  1. #1
    in a php page, it gets data from mysql db like this:

    <object type="asd" class="dfdf" width="{width}" height="{height}" name="fdf"></object>

    now i want my php page, replace those {width} & {height} which r already declared in that php file as $width=100 $height=100
     
    dracula51, Nov 21, 2009 IP
  2. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    
    <object type="asd" class="dfdf" width="<?php echo $width;?>" height="<?php echo $height;?>" name="fdf"></object>
    
    
    PHP:
    The above should work if not try this...

    
    
    <object type="asd" class="dfdf" width="'.$width.'" height="'.$height.'" name="fdf"></object>
    
    
    PHP:
     
    pixmania, Nov 21, 2009 IP
  3. dracula51

    dracula51 Peon

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    haha
    no man. thats not i wanted. it is {width} & i hav to use it...not those things

    by the way....str_replace is the solution...hitted my mind after opening this thread
     
    dracula51, Nov 21, 2009 IP
  4. zhulq

    zhulq Peon

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    zhulq, Nov 21, 2009 IP
  5. emed

    emed Peon

    Messages:
    70
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    something like this?
    $template = <= Data from the database
    
    $template = str_replace("{width}",$width,$template);
    $template = str_replace("{height}",$height,$template);
    PHP:
    str_replace work with arrays too:
    $template = <= Data from the database
    
    $search = array{"{width}","{height}"};
    $replace = array{$width,$height};
    
    $template = str_replace($search,$replace,$template);
    PHP:
     
    emed, Nov 21, 2009 IP
  6. dracula51

    dracula51 Peon

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    tnc guys. i've solved it :)
    & tnx for the link, zhulq
     
    dracula51, Nov 21, 2009 IP