I've set up a section on my site, to switch out content, based on the DIV ID called, but the initial "value" results in an error, if the variable isn't in the url.
the error i get:Undefined index: item
item is my variable.
My PHP is this:
<?php
$url = 'file.php';
$content = file_get_contents( $url );
$item = $_GET[ 'item' ];
switch ( $item ) {
case "content1":
$start = explode( '<div id="content1">', $content );
$end = explode( "</div>", $start[ 1 ] );
echo $end[ 0 ];
break;
case "content2":
$start = explode( '<div id="content2">', $content );
$end = explode( "</div>", $start[ 1 ] );
echo $end[ 0 ];
break;
case "content3":
$start = explode( '<div id="content3">', $content );
$end = explode( "</div>", $start[ 1 ] );
echo $end[ 0 ];
break;
default:
$start = explode( '<div id="content1">', $content );
$end = explode( "</div>", $start[ 1 ] );
echo $end[ 0 ];
}?>
So the code works fine if I append ?item=content1
at the end of my url, however, on initial visit (without the ?item=
at the end) i get the above error ( Undefined index: item
)
What can I do so that if someone visits say index.php I won't get the error, and throw up the default called content?