dimakritchevski Posted April 19, 2009 Share Posted April 19, 2009 Hey there, This is a simple problem with php code that I'm sure anyone with a decent knowledge of php can fix.... Here's what's going on: I'm sending adwords traffic to a website with the following piece of code added on to the end of the destination url: http://url.com/?KeyWord=Product Name I'm then inserting the snippet as follows to add the KeyWord into my H1 tag <H1><?php echo $_GET['KeyWord']; ?></H1> The question is... how do I add a parameter to specify that if the KeyWord variable is blank to insert "Default Text" rather than just leaving KeyWord blank. --------------------------------------------------------------------------- Just to be abundantly clear Destination URL: http://url.com/?KeyWord=Weight Watchers Headline: <?php echo $_GET['KeyWord']; ?> I want it to be more like... Headline: "KeyWord" and if KeyWord is blank to default to "Lite N Easy". I'm sure this is an easy problem to fix for anyone who knows their stuff. Thanks in advance! - Dima Link to comment https://forums.phpfreaks.com/topic/154766-solved-simple-php-question-need-help/ Share on other sites More sharing options...
MatthewJ Posted April 19, 2009 Share Posted April 19, 2009 Depends... If ti is not going to be there at all: <?php if(isset($_GET['KeyWord'])) { echo $_GET['KeyWord']; } else { echo "Default Text"; } ?> Or if it is going to be there but be blank <?php if($_GET['KeyWord'] != "") { echo $_GET['KeyWord']; } else { echo "Default Text"; } ?> Link to comment https://forums.phpfreaks.com/topic/154766-solved-simple-php-question-need-help/#findComment-813855 Share on other sites More sharing options...
play_ Posted April 19, 2009 Share Posted April 19, 2009 A neat ternary works too. $keyword = ( (isset($_GET['KeyWord'])) && ($_GET['KeyWord'] != '') ) ? $_GET['KeyWord'] : 'Lite n Easy'; echo $keyword Link to comment https://forums.phpfreaks.com/topic/154766-solved-simple-php-question-need-help/#findComment-813862 Share on other sites More sharing options...
DarkSuperHero Posted April 19, 2009 Share Posted April 19, 2009 Just some shorthand :-P <?php $someKey = ($_GET['KeyWord'] != '') ? $_GET['KeyWord'] :'Default Text'; echo $someKey; the speed of some responses....im a slow typist i suppose... :-P Link to comment https://forums.phpfreaks.com/topic/154766-solved-simple-php-question-need-help/#findComment-813863 Share on other sites More sharing options...
dimakritchevski Posted April 19, 2009 Author Share Posted April 19, 2009 Implemented MatthewJ's code and got it all working! Thanks a heap to ALL of you that replied so quickly though.. you guys rock. Problem solved. Please close this thread. Link to comment https://forums.phpfreaks.com/topic/154766-solved-simple-php-question-need-help/#findComment-813917 Share on other sites More sharing options...
Maq Posted April 19, 2009 Share Posted April 19, 2009 Problem solved. Please close this thread. Next time, there is a tab labeled [sOLVED]. Link to comment https://forums.phpfreaks.com/topic/154766-solved-simple-php-question-need-help/#findComment-814039 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.