php function in page title

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
AutoRunway
Forum Newbie
Posts: 9
Joined: Wed Apr 07, 2010 2:38 pm

php function in page title

Post 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
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: php function in page title

Post by flying_circus »

Code: Select all

<title>Current Weather in <?php print $weather->get_location(); ?></title>
AutoRunway
Forum Newbie
Posts: 9
Joined: Wed Apr 07, 2010 2:38 pm

Re: php function in page title

Post by AutoRunway »

flying_circus wrote:

Code: Select all

<title>Current Weather in <?php print $weather->get_location(); ?></title>
Hmmm... it's not working :(
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: php function in page title

Post 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?
AutoRunway
Forum Newbie
Posts: 9
Joined: Wed Apr 07, 2010 2:38 pm

Re: php function in page title

Post 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>
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: php function in page title

Post 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>

';
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
AutoRunway
Forum Newbie
Posts: 9
Joined: Wed Apr 07, 2010 2:38 pm

Re: php function in page title

Post by AutoRunway »

Great thanks Shawn :)
AutoRunway
Forum Newbie
Posts: 9
Joined: Wed Apr 07, 2010 2:38 pm

Re: php function in page title

Post 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?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: php function in page title

Post 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]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
AutoRunway
Forum Newbie
Posts: 9
Joined: Wed Apr 07, 2010 2:38 pm

Re: php function in page title

Post by AutoRunway »

Yep that did the trick, thanks again Shawn :)
Post Reply