I have two files :
- index.php
- condition.php
condition.php hold some switch statements. I wrote only one case,but there is more than 20 cases.ow do i include the another file in index.php for showing the output..here is my code:
//index.php
<?
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=dhaka');
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
?>
<html>
<head>
<title>Google Weather API</title>
</head>
<body>
<h1><?= print $information[0]->city['data']; ?></h1>
<h2>Today's weather</h2>
<div class="weather">
<?php
include 'condition.php';
?>
<span class="condition">
<?= $current[0]->temp_f['data'] ?>° F,
<?= $current[0]->condition['data'] ?>
</span>
</div>
</body>
</html>
here is the condition.php
switch ($cond)
{
case "Mostly Cloudy":
$col="/test/images/weather/mostly_cloudy.png";
echo "<img src=\"$col\" alt=\"\"/>";
break;
case "Thunderstorm":
$col="/test/images/weather/thunderstorm.png";
echo "<img src=\"$col\" alt=\"\"/>";
break;}
I posted 2 cases but there is more than 20 cases.
You are doing it the right way using
<?php include("condition.php"); ?>, all you need to do is define$condso the switch actually does something. Or you can create a function from condition.php and use it that way. That’s probably a “cleaner” way to work.Example: