• On Wednesday, 19th February between 10:00 and 11:00 UTC, the forum will go down for maintenance. Read More

Simple PHP help please?

Entrepreneur

BANNED
Joined
Oct 12, 2007
Messages
439
Reaction score
391
I'm building a page and for tracking purposes I'm trying to use switch to create a variable which is a link ($link) that can then be shown throughout the page, by echoing this new variable.

What i need to do is, check the url, (is this index or other) and if index it displays one URL everywhere $link appears, and using the switch default, i'll display another link for all other pages.

The code below worked until i decided to use it as a variable.

Please help my lovely Blackhat Friends. Oh, and the error is in line 2, so probably something to do with me trying to assign the output to a variable?

btw, $val is the page and my php knowledge is very low! :)

Code:
<?php 
$link = switch ($val) {
case "index":
echo "http://buy.php";
break;
default:
echo "http://optin.php";
}
?>

Thanks
 
So depending on what $val is you want a certain URL to be displayed everywhere you put the $link variable?

PHP:
<?php 
switch ($val) 
{
case "index":$link =  "http://buy.php";
break;
default: $link =  "http://optin.php";
}
?>

Now to dispay the URL everywhere, type something like:

PHP:
<?php print $link; ?>


Hope I have understood what you were after!
 
Excellent! That's exactly what i needed! Thank you. :D

On a side note i didn't realise that you don't need to echo the $link for it to then become a variable, which is cool and also, what's the difference between print and echo, because i was plannning to use the link as:

PHP:
<?php echo "$link"; ?>

Thanks again! I really appreciate it. +rep
 
Not really sure if there is any difference between print and echo :)
Some pro PHP person will probably tell you the difference, but I am a mere PHP hacker so get something up thats dirty but works!
 
Not really sure if there is any difference between print and echo :)
Some pro PHP person will probably tell you the difference, but I am a mere PHP hacker so get something up thats dirty but works!

They can be used interchangeably most of the time. But if you really want to know the difference, check out

Code:
http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40
 
Back
Top