html5 - Change Web Text Using PHP Based on URL Parameter -
i'm looking change the article a/an in webpage based on parameter passed via url. example, i've got mywebpage.com/?page&qry=dog url, want a/an articles "a" dog (vs "an" aardvark qry). i'm trying use code below, i'm getting parse error time try load page.
<?php in_array(substr($_get['qry'],0,1), array('a','e','i','o','u')) ? 'an' 'a'; ?>
if tried if/else statement, lead same result.
<?php if(in_array(substr($_get['qry'],0,1), array('a','e','i','o','u'))):'an':'a'; ?>
i'm sure i'm missing simple, related attempt insert snippet amongst standard html text; can spot error(s)?
this error back:
parse error: parse error in c:\program files (x86)\apache software foundation\apache2.2\htdocs\testsite\html\page.html.php on line 117
thank you!
<?php in_array(substr($_get['qry'],0,1), array('a','e','i','o','u')) ? 'an' : 'a'; ?>
removing if()
. ternary operators don't use if()
, that's they're for, conditionally check in 1 go.
reference:
footnotes: (op)
"perfect! also, tries use in future, i'd forgotten echo statement (which remedied...
<?php echo ...
if add above answer i'll sure mark such. thank help!"
Comments
Post a Comment