Page 1 of 1

php function in page title

Posted: Wed Apr 07, 2010 2:47 pm
by AutoRunway
i need get_location in the title of the page ... $weather->get_location() . ":
so title would be something like <title>Current Weather in get_location</title>

Code: Select all

$output .= '<p>This is the current weather in ' .
          $weather->get_location() . ":</p>\n<blockquote>\n" .
          $text->print_pretty() . "\n</blockquote>\n" .
          "<p></p>\n<blockquote>\n" .
          '<img src="' . $icons->get_sky_image() .
          '" height="50" width="80" border="1" alt="Current weather in ' .
          $weather->get_location() . '" /> ' .
          
Im learning as i go, please help

Re: php function in page title

Posted: Wed Apr 07, 2010 3:01 pm
by flying_circus

Code: Select all

<title>Current Weather in <?php print $weather->get_location(); ?></title>

Re: php function in page title

Posted: Wed Apr 07, 2010 3:14 pm
by AutoRunway
flying_circus wrote:

Code: Select all

<title>Current Weather in <?php print $weather->get_location(); ?></title>
Hmmm... it's not working :(

Re: php function in page title

Posted: Wed Apr 07, 2010 3:36 pm
by flying_circus
AutoRunway wrote:
flying_circus wrote:

Code: Select all

<title>Current Weather in <?php print $weather->get_location(); ?></title>
Hmmm... it's not working :(
Define "not working". Is your $weather object created and populated before you're trying to access it?

Re: php function in page title

Posted: Wed Apr 07, 2010 3:54 pm
by AutoRunway
Thanks for your time and consideration. I'm not sure how its created and populated. Here's the entire code of my page...

Code: Select all

<?php
error_reporting(E_ALL);

/* We store the time */
$start_time = explode(' ', microtime());

require('phpweather.php');
require('pw_utilities.php');

$weather = new phpweather();

$output = '<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "DTD/xhtml1-transitional.dtd">
<html>
<head>
  <link rel="stylesheet" type="text/css" href="pw_style.css" />
  <title>Current Temperature in <?php print $weather->get_location(); ?></title>
  <meta name="description" content="Current temperature and weather reports from around the world"
</head>
<body>

<p>Find the current temperature and weather conditions in your area...</p>

';


if (empty($HTTP_GET_VARS['cc'])) {
  $cc = '';
} else {
  $cc = trim(stripslashes($HTTP_GET_VARS['cc']));
}

if (empty($HTTP_GET_VARS['icao'])) {
  $icao = '';
} else {
  $icao = trim(stripslashes($HTTP_GET_VARS['icao']));
}

$languages = get_languages('text');

if (empty($HTTP_GET_VARS['language']) ||
    !in_array($HTTP_GET_VARS['language'], array_keys($languages))) {
  $language = 'en';
} else {
  $language = stripslashes($HTTP_GET_VARS['language']);
}

if ($icao != '') {
  $weather->set_icao($icao);
  /* icao was passed, we resolve country code */
  $cc_temp = $weather->get_country_code();
  if ($cc_temp === false) {
    /* turn icao off, it is not valid */
    $icao = '';
  } else {
    /* use resolved country code */
    $cc = $cc_temp;
  }
}

/* Always display country selection */
$output .= '<form action="index.php" method="get">' . "\n"
	.'<p>' . get_countries_select($weather, $cc)
	.' <input type="submit" value="'
	.($cc == '' ? 'Submit country' : 'Change country').'" />'
	.'<input type="hidden" name="language" value="'.htmlspecialchars($language).'"> '
	. "</p>\n</form>\n";

if (! empty($cc)) {
  /* Show stations selection for particular country ($cc). */
  $output .= '<form action="index.php" method="get">' . "\n<p>"
          . get_stations_select($weather, $cc, $icao)
          . get_languages_select($language)
          . '<input type="submit" value="Submit location">'
          . "</p>\n</form>\n";
}

if (! empty($icao)) {
  /* We should only display the current weather if we have station ($icao) */
  require(PHPWEATHER_BASE_DIR . "/output/pw_text_$language.php");
  $type = 'pw_text_' . $language;
  $text = new $type($weather);
  
  require(PHPWEATHER_BASE_DIR . "/output/pw_images.php");
  $icons = new pw_images($weather);
  
  $output .= '<p>This is the current weather in ' .
          $weather->get_location() . ":</p>\n<blockquote>\n" .
          $text->print_pretty() . "\n</blockquote>\n" .
          "<p></p>\n<blockquote>\n" .
          '<img src="' . $icons->get_sky_image() .
          '" height="50" width="80" border="1" alt="Current weather in ' .
          $weather->get_location() . '" /> ' .
          '<img src="' . $icons->get_winddir_image() .
          '" height="40" width="40" border="1" alt="Current wind in ' .
          $weather->get_location() . '" /> ' .
          '<img src="' . $icons->get_temp_image() .
          '" height="50" width="20" border="1" alt="Current temperature in ' .
          $weather->get_location() . '" />' .
          "\n</blockquote>\n";
}

if (empty($text)) {
  header('Content-Type: text/html; charset=ISO-8859-1');
} else {
  header('Content-Type: text/html; charset=' . $text->get_charset());
}

echo $output;

$end_time = explode(' ', microtime());

$diff = ($end_time[0] + $end_time[1]) - ($start_time[0] + $start_time[1]);

?>


</body>
</html>

Re: php function in page title

Posted: Wed Apr 07, 2010 4:14 pm
by AbraCadaver

Code: Select all

$output = '<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "DTD/xhtml1-transitional.dtd">
<html>
<head>
  <link rel="stylesheet" type="text/css" href="pw_style.css" />
  <title>Current Temperature in ' . $weather->get_location() . '</title>
  <meta name="description" content="Current temperature and weather reports from around the world"
</head>
<body>

<p>Find the current temperature and weather conditions in your area...</p>

';

Re: php function in page title

Posted: Wed Apr 07, 2010 4:21 pm
by AutoRunway
Great thanks Shawn :)

Re: php function in page title

Posted: Thu Apr 08, 2010 2:14 pm
by AutoRunway
Putting this in the title makes the location always the same so no matter what is displayed on the page, the location in the page title is always Aalborg, Denmark :(

Code: Select all

<title>Current Temperature in ' . $weather->get_location() . '</title>


Any ideas why the location never changes?

Re: php function in page title

Posted: Thu Apr 08, 2010 3:00 pm
by AbraCadaver
AutoRunway wrote:Putting this in the title makes the location always the same so no matter what is displayed on the page, the location in the page title is always Aalborg, Denmark :(

Code: Select all

<title>Current Temperature in ' . $weather->get_location() . '</title>


Any ideas why the location never changes?
I'm not sure what all the code is doing, but you probably want to move the code from my previous post down just before this line:

[text]/* Always display country selection */[/text]

Re: php function in page title

Posted: Thu Apr 08, 2010 4:22 pm
by AutoRunway
Yep that did the trick, thanks again Shawn :)