Banner Rotator Script Problem

Hi All
I am using a very small PHP banner rotator script on a site and I am having problems making the banner URLs open in a new window.

Here is the code:

<?php //You will have to change the ban1, ban2, and ban3 variables. You can change these links to point at the images you want displayed. //You will have to change the url1, url2, and url3 variables. You want these to be urls of the pages you want to link to. $ban1 = "http://www.trackdaymagazine.com/banners/121banner.jpg"; $url1 = "http://www.121drive.com"; $ban2 = "http://www.trackdaymagazine.com/banners/racefit_banner.gif"; $url2 = "http://www.racefit.co.uk"; //Random number between 1 and number of banners. $randomNum = rand (1,2); //Select the banner of the random number $image = ${'ban'.$randomNum}; //Url of the random number $url= ${'url'.$randomNum}; //Prints out the link of the banner and the image of the banner Print ""; ?>

So how do I make the URLs open in a new window?

Thanks in advance


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You will need to find the part of the script that actually creates the hyperlink, and extend it to include a target=“_blank” attribute. This will not be in the part where you define the arrays of images and urls, but down near the end, after the random number generator.

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Walter

The problem I have here is the severe lack of knowledge I have with PHP. If I sent you the script, would you be able to tell me exactly where I should insert this attribute? I don’t seem to be able to copy the script in here, perhaps there is a way of doing so.

Kind regards


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Sure. Your problem is in here:

Print "<a href=".$url." mce_href=".$url.">
	<img src=".$image." border=0></a>";

Make this line read thusly:

Print "<a href=".$url." href=".$url." target="_blank">
	<img src=".$image." border=0></a>";

I don’t know where the mce_href thing comes from, but that looks like
a mistake there, and the target is just another property of the A
tag, parallel to the href or title properties.

As far as getting code to show up as code, use four spaces to indent
each line of code, and make sure that you have at least two returns
(line feeds) between a block of code and any adjacent normal text. If
you are sending in your code from e-mail, take special care to make
sure that your lines of code are very short. The automatic line-
wrapping that happens in the list-server will otherwise break your
code into new lines at awkward moments, breaking the formatting.

Walter

On Mar 24, 2008, at 10:00 PM, DillyDog wrote:

Thanks Walter

The problem I have here is the severe lack of knowledge I have with
PHP. If I sent you the script, would you be able to tell me exactly
where I should insert this attribute? I don’t seem to be able to
copy the script in here, perhaps there is a way of doing so.

Kind regards


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Walter, but it still doesn’t work. I tried it exactly as you said, and with keeping in the mce_href bit, and all I get when I load the page is this:

Parse error: syntax error, unexpected T_STRING in /content/StartupHostPlus/t/r/trackdaymagazine.com/web/trackdays/index.php on line 149

It does work perfectly as-is, but as I said, all I want is for the links to open in a new window.

Thanks again


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Are you using a content management system that uses the TinyMCE editor? That’s the only reason I can think of to have the mce_href property there. Otherwise, it’s not HTML.

As far as your PHP error goes, you are completely leaving out your quote marks when you are concatenating the URL together. Single-quotes can enclose double-quotes without escaping, and double-quotes can enclose single-quotes without escaping, but otherwise, you have to add a backslash before each same-type quote that you wish to retain in an echo or print statement.

Let’s say you wanted to have the following image tag print out:

<img src="/path/to/image.gif" height="20" width="200" alt="Alt text" />

If you put that entire line inside of single-quotes and made it a print statement, it would work.

But if you put that entire line inside of double-quotes, you would have to go through the text and add a backslash in front of each double-quote that you wanted to appear in the output or else what the PHP engine would see was this:

print "<img src=" and then an error happens here>;

That’s because the first double-quote inside your string effectively ends the print command, and everything after that has to be valid PHP code in order for processing to continue.

Try this: wrap your print statement in single quotes. Then look through the line for periods (dots, full-stops, whatever you call them in your version of English). Each one of these dots in a line of PHP is what’s called a concatenation operator. It means that you glue two strings of text together by mushing one onto the end of the other. So everywhere you see this, make sure that the string is ended with a single-quote. It’s also a good idea to space these out so you can see them. In the image tag example above, you would make it look like this:

print '<img src="' . $image_path . '" height="' . $image_height . '" width="' $image_width . '" alt="' . $image_alt . '" />';

Look carefully at the line above. Note that each bit of text that is being mashed together is itself completely encapsulated within single-quotes. There are double-quotes started and ended inside of adjacent string segments, but there are no mixed quotes happening between the dot operators. If for some reason I needed to print out a literal single-quote within the output text, I would need to escape it with a backslash: '.

Now if you wanted to do the same thing, but use the same type of quote mark both inside the text and as the container for the text, you would need to add a backslash before each quote mark that you wanted to retain in your final output code.

I realize that I left the quoting entirely out of my example, and if you copied and pasted what I posted earlier, it wouldn’t work. But I can’t see how your code would have worked either, unless somewhere the backslashes are being removed from the code you have added to your example.

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Are you using a content management system that uses the TinyMCE editor? That’s the only reason I can think of to have the mce_href property there. Otherwise, it’s not HTML.

Yes, I’m using WebYep, but this script isn’t within a WebYep element.

I’m afraid you have me completely confused now. As I said at the beginning, I know very little about PHP, or coding in general (that’s why I love Freeway!)

Would it be at all possible for me to send you the script so you can see it in it’s entirety and possibly tweak it for me to make it work? I’m starting to wish I hadn’t told the client that the links could be made to open a new window!

Then I think I will have to get some proper lessons in PHP (when I have time).

Thanks a Million.

Tim


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options