Space/ Symbols/ Text, etc between multiple ads

Discussion in 'Co-op Advertising Network' started by nick j, Dec 15, 2004.

  1. #1
    Hi

    I'm not good using PHP, and I want to use space or symbols (- / * | etc...) between each ad (I'm using 5 ads)

    The code on include is:

    <?php
    ini_set ("include_path", ini_get ("include_path") . ':../:../../:../../../:../../../../');
    include ('ad_network.php');
    echo $ad_network[0] . ' ';
    include ('ad_network.php');
    echo $ad_network[1] . ' ';
    include ('ad_network.php');
    echo $ad_network[2] . ' ';
    include ('ad_network.php');
    echo $ad_network[3] . ' ';
    include ('ad_network.php');
    echo $ad_network[4];
    ?>


    You can see at www.anywhere-phone-rental.com



    Any suggestion?
     
    nick j, Dec 15, 2004 IP
  2. vlead

    vlead Peon

    Messages:
    215
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use this to add the | symbol after the 1st ad
     echo $ad_network[0] . ' \| '; 
    PHP:
    Pipe symbol | is a operator in PHP and has a special meaning... you need to escape it using a backslash \
     
    vlead, Dec 15, 2004 IP
  3. rvarcher

    rvarcher Peon

    Messages:
    69
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    //  $ad_network is an array.
    //  implode is a function that 'glues' and array together with
    //   whatever glue you specify and returns a single string.
    $my_glue = ' | ';   //  or whatever you want in between each ad. maybe  <br>
    $all_5_ads = implode($my_glue,$ad_network);
    echo $all_5_ads;
    
    PHP:
    a pipe does not need to be escaped. anything in single quotes does not need to be escaped.
     
    rvarcher, Dec 15, 2004 IP
    T0PS3O likes this.
  4. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Nice bit of code, that will sort dozens of Coop people out!
     
    T0PS3O, Dec 15, 2004 IP
  5. nick j

    nick j Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for all!!
     
    nick j, Dec 15, 2004 IP
  6. rvarcher

    rvarcher Peon

    Messages:
    69
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    No problem. Glad to help out.
     
    rvarcher, Dec 15, 2004 IP
  7. eeve

    eeve Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You don't even have to escape the pipe in double quotes. The fact that it is in a string means it that it won't be treated as an operator.

    The main things you have to escape are other (inner) single and double quotes and dollar signs.
     
    eeve, Dec 15, 2004 IP
  8. General Grant

    General Grant Well-Known Member

    Messages:
    318
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    160
    #8
    This one needs to be stickied!

    Damn, this worked on another script, but now I'm getting this: "Warning: implode(): Bad arguments."
     
    General Grant, Dec 27, 2004 IP
  9. rvarcher

    rvarcher Peon

    Messages:
    69
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #9
    That usually means the array variable you're trying to implode is not defined or is not an array. You've included the ad_network.php file successfully? Test by trying:

    
    echo "ad_network[0]: $ad_network[0]";
    
    PHP:
     
    rvarcher, Dec 28, 2004 IP