Cell Phones - Auto Loans - Dominios - Loans - Car Credit

PDA

View Full Version : Space/ Symbols/ Text, etc between multiple ads


nick j
Dec 15th 2004, 9:10 am
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?

vlead
Dec 15th 2004, 9:17 am
Use this to add the | symbol after the 1st ad
echo $ad_network[0] . ' \| ';

Pipe symbol | is a operator in PHP and has a special meaning... you need to escape it using a backslash \

rvarcher
Dec 15th 2004, 9:36 am
// $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;


a pipe does not need to be escaped. anything in single quotes does not need to be escaped.

T0PS3O
Dec 15th 2004, 9:45 am
Nice bit of code, that will sort dozens of Coop people out!

nick j
Dec 15th 2004, 9:50 am
Thanks for all!!

rvarcher
Dec 15th 2004, 10:36 am
No problem. Glad to help out.

eeve
Dec 15th 2004, 11:12 am
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.

General Grant
Dec 27th 2004, 6:43 pm
// $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;


a pipe does not need to be escaped. anything in single quotes does not need to be escaped.
This one needs to be stickied!

Damn, this worked on another script, but now I'm getting this: "Warning: implode(): Bad arguments."

rvarcher
Dec 28th 2004, 9:02 am
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]";