New to PHP and this is my first real go...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Pegasus
Forum Newbie
Posts: 3
Joined: Thu Jul 11, 2002 12:32 am

New to PHP and this is my first real go...

Post by Pegasus »

This one is something that i am going to publish. Its very basic, but it is doing something wrong :(

Where it states the links in the array as <a href = "$site1">, thats what its out putting it as..so the link the browser is looking for is http://rytek.info:81/pegasus/$site1

Any Ideas?

Code: Select all

<?
///////////////////////////////////////////////////
// Script by Andy Howard from                //
//Pegasus WebPages                              //
//e-mail: pegasus@postnuclear.net        //
//website: http://rytek.info:81/pegasus  //
//                                                           //
//Links v1.0                                           //
//-----------------------------------------------//
//Free for distripution and Copy               //
//If you change it for the better              //
//Please e-mail it to me                          //
//////////////////////////////////////////////////

//----------------------------------------------

//Enter the Address of the Sites
//e.g. $site1= "the address of the site";

$site1 = "http://rytek.info:81/";
$site2 = "http://www.postnuclear.net/";
$site3 = "http://www.annihilation.info/";
$site4 = "http://www.zerovoid.net/";
$site5 = "http://www.deviantart.com/";
//You can add more links, all you have to do is copy and paste and change the # ($site#) to continue up

//----------------------------------------------

// Change the number to the highest number from above

$topnumber = "5";

//----------------------------------------------

//Enter the Text of the quote:
//e.g. <a href = "$site1">YOUR TEXT HERE</a>

$test = array(1 => '<a href = "$site1">http://rytek.info:81/</a>',
                                 2 => '<a href = "$site2">http://www.postnuclear.net/</a>',
                                           3 => '<a href = "$site3">http://www.annihilation.info</a>',
                                           4 => '<a href = "$site4">http://www.zerovoid.net/</a>', 
                                           5 => '<a href = "$site5">http://www.deviantart.com/</a>');

//----------------------------------------------

//Don't change this.
                                           
$rand = rand(1,$topnumber);

//----------------------------------------------

//Place this anywhere to print your links
//IMPORTANT IT MUST NOT BE IN THE SAME PHP BRACKETS (<? )  AS THE REST OF THE SCRIPT

//----------------------------------------------
?>
<? echo $test&#1111;$rand];?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

It's because the string's in single quotes and PHP ignores stuff that's in strings enclosed in single quotes so:

Code: Select all

$test = array(
     1 => '<a href = "'.$site1.'">http://rytek.info:81/</a>',
     2 => '<a href = "'.$site2.'">http://www.postnuclear.net/</a>',
     3 => '<a href = "'.$site3.'">http://www.annihilation.info</a>', 
     4 => '<a href = "'.$site4.'">http://www.zerovoid.net/</a>', 
     5 => '<a href = "'.$site5.'">http://www.deviantart.com/</a>'
);
Should work a bit better.

Mac
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

hey... i got bored, steal it if you want

Code: Select all

<?

/*
THE URLS, if you want to add one just put in another line using the next number..
and dont forget to add a comma to the line before it :-D
Also, if you add a URL, Add a name too!
*/
$urls = array(

	1 => 'http://foo.com',
	2 => 'http://bar.com',
	3 => 'http://foobar.com',
	4 => 'http://www.ice-on-fire.net'

);


/*
THE NAMES, the names that you want the links, make sure the number of the name
 corresponds to the number of the URL, and just like before, if you add one.. use the next
number, and dont forget to put a comma on the line before it :p
*/
$names = array(

	1 => 'foo',
	2 => 'bar',
	3 => 'foobar',
	4 => 'my site'

);

/* 
THE SCRIPT, dont edit :-)
*/


$size = sizeof($urls);
$n = rand(1, $size);

echo "<a href="$urls&#1111;$n]">$names&#1111;$n]</a>";

?>
Post Reply