I run a small, specialist classical music listings web site and have the venue name, address, telephone number etc. (with html mark up) in a heredoc, stored in an external php file. All I do is write:
The Mango String Quartet is performing at
<?php echo $local_arts_centre; ?>
and the venue details are printed neatly laid out.
I have written a search facility which searches the text but does not search the variables, the phrase "mango string quartet" would be found, but not "local arts centre".
I have searched the web and PHP books but can not find the solution. Any ideas would really be appreciated.
you're looking for isset($var)
if a variable isn't set than isset($var) == null
.
Check 'isset' it here: http://php.net/manual/en/function.isset.php
I don't know if I get it right but...
HTML code
<!-- list of music -->
<a href="somefile.php?music=happybirthday">Happy Birthday</a>
<a href="somefile.php?music=rockandroll">Rock and Roll</a>
<a href="somefile.php?music=raps">Raps</a>
And at somefile.php
<?php
// array for locations if just a few
$locations = array("here and there", "ther eand here");
// checking if the name 'music' has a value
if (isset($_GET['music'])) {
$music = $_GET['music'];
// since we have the value of music, lets put some locations to them.
switch ($music) {
case 'happybirthday':
echo "The location is at " . $locations[0]; //hereandthere
break;
case 'rockandroll':
echo "The location is at " . $locations[0]; //hereandthere
break;
case 'raps':
echo "The location is at " . $locations[1]; //thereandhere
break;
default:
echo "Please select a music"; // or something
}
} else {
echo "Please select a music"; // or something
}
?>
Many thanks for your replies. What I am trying to do is search a web page of concert listings, for example (obviously very simplified).
<div>
Thursday, 17 May 2012
The Mango String Quartet will be playing Beethoven, Tavener and Terry Riley at:
<?php echo $local_arts_centre; ?>
Concert starts at 7.30pm
Tickets £10.00
</div>
When I do a search through the html everything is found except the contents of the heredoc $local_arts_centre (which contains the venue's address, telephone number etc.). Is there a way of parsing the heredoc, oviously it shows up on the web page but not when the code is searched?
It is not really essential but it would be useful if someone could search for concerts at a specific venue, or in a specific city.
There is a work around of course but it is not that neat. I could I suppose write:
<?php echo $local_arts_centre; /* Local Arts Centre London */ ?>
This means "Local Arts Centre" and "London" would be found.
Anyway thank you for your suggestions so far, I have found so many ideas on the forum already.