Passing a default query phrase if no query phrase is specified

The following is a script I am using to prepopulate a page with some RSS results based in a query that is passed to it via a url. For example:

http://www.test.com?m=My%20Phrase
http://www.test.com?m=David%20Beckham
etc ...

What I cannot work out how to do is how can I specify a default phrase if the url does not have a query string then replace the $keyword variable with the default phrase. The file sits in the root as index.php.

PHP Code:

<? $strM = $_GET['m']; $strR = "_"; $keyword = str_replace($strR, ' ', $strM); ?>
<html>
<head>
<title><? echo $keyword; ?></title>
<meta name="description" content="Information, articles, and news about <? echo $keyword; ?>">
<meta name="keywords" content="<? echo $keyword; ?>">
</head>
<body>
<h1><? echo $keyword; ?></h1>
<br>
<?php $strM = $_GET['m']; $strR = "_"; $strf = str_replace($strR, ' ', $strM);
$f = 'http://news.search.yahoo.com/usns/ynsearch/categories/news_story_search_rss/index.html?p='.urlencode($strf);
require_once '/path/to/carp.php';
CarpClearCache(1);
CarpConf('cborder','');
CarpConf('iorder','desc');
CarpConf('bi','<p>');
CarpConf('ai','</p>');
CarpConf('poweredby','');
CarpShow("$f"); ?>
</body>
</html>

Any help would be appreciated.

Thanks
msryhajwAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

alain34Commented:
you need to do something like that

if (isset($_GET["m"])) {
   $strM = $_GET['m'];
   }
else {
   $strM = 'default';
   }
dereshCommented:
replace this:

<? $strM = $_GET['m']; $strR = "_"; $keyword = str_replace($strR, ' ', $strM); ?>

with this:

<? $strM = isset($_GET['m']) ? $_GET['m'] : "default keyword"; $strR = "_"; $keyword = str_replace($strR, ' ', $strM); ?>

if the variable "m" is set in your query string then $strM variable gets its value otherwise gets value "default keywords".

msryhajwAuthor Commented:
Deresh,

That seems to work for replacing the keyword variable but the query for default keywords is not passed to rss part:

<?php $strM = $_GET['m']; $strR = "_"; $strf = str_replace($strR, ' ', $strM);
$f = 'http://news.search.yahoo.com/usns/ynsearch/categories/news_story_search_rss/index.html?p='.urlencode($strf);

Thanks
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

alain34Commented:
you just need to duplicate the code from deresh or myself to the definition of $strf
msryhajwAuthor Commented:
Like this:

<?php isset($_GET['m']) ? $_GET['m'] : "default keyword"; $strR = "_"; $strf = str_replace($strR, ' ', $strM);
$f = 'http://news.search.yahoo.com/usns/ynsearch/categories/news_story_search_rss/index.html?p='.urlencode($strf);

?
alain34Commented:
like that

if (isset($_GET["m"])) {
   $strM = $_GET['m'];
   }
else {
   $strM = 'default keyword';
   }
$strR = "_";
$strf = str_replace($strR, ' ', $strM);
$f  = 'http://news.search.yahoo.com/usns/ynsearch/categories/news_story_search_rss/index.html?p='.urlencode($strf);
dereshCommented:
<?php isset($_GET['m']) ? $_GET['m'] : "default keyword"; $strR = "_"; $strf = str_replace($strR, ' ', $strM);
$f = 'http://news.search.yahoo.com/usns/ynsearch/categories/news_story_search_rss/index.html?p='.urlencode($strf);
// $f is only a URL to rss feeds you wish so you should open that URL with
$rss_xml_data = file_get_contents($f);

?>

now in $rss_xml_data you should get your rss feeds as returned from yahoo! (and parse it somehow - its XML you could use SAX or DOM).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.