Use [ php ] tags when posting PHP code.

Nice try.
Your problem is that you're trying to pass dynamic values into the "default" value of a variable. Unfortunantely, default variables must be clearly defined, so that's a nono. Plus, the variables don't exist!
Try this, using the new class Map (since classes are traditionally named with uppercase). Untested, of course.
Code: Select all
<?php
class Map {
var $addr;
var $csz;
var $country;
var $base_link = "http://maps.yahoo.com/maps_result";
var $link;
function Map() {
$this->addr = $_POST['address'];
$this->csz = $_POST['csz'];
$this->country = $_POST['country'];
$this->link = $this->base_link .
$this->parseURL(
array('addr'=>$this->addr,
'csz'=>$this->csz,
'country'=>$this->country,
'new'=>'1')
);
}
function parseURL($array) {
$output = '?';
$first = true;
foreach($array as $key => $value) {
if (!$first) {
$output .= '&';
} else {
$first = false;
}
$output .= $key;
$output .= '=';
$output .= urlencode($value);
}
return $output;
}
function displayLink() {
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Link to the Map</title>
</head><body>
<p><a href="<?php echo $this->link; ?>" class="five">Link to the Map</a></p>
</body></html>
<?php
}
}
$map = new Map;
$map->displayLink();
?>
Update - Oops, forgot to return $output. Fixed.
Update 2 - Hmmm... it just occured to me: using Objects probably is overkill for this particular task. You should either stay procedural, or maybe make the class more abstract.
Update 3 - <? to <?php. Shorttags is evil.
Update 4 - Actually tested it. Boy, loads of errors. Moved variable assignment inside constructor, changed parseURL() to $this->parseURL(), and all that other good stuff. Seems to work now.
Update 5 - $this->$addr to $this->addr. Big difference.