Change web text using PHP based on URL parameter

I want to change the a / a article on a web page based on a parameter passed through a URL. So, for example, I have mywebpage.com/?page&qry=dog as a URL, so I would like any a / a articles to be a "dog" (against aardvark it was qry). I'm trying to use the code below, however, I get a parsing error anytime when I try to load the page.

<?php in_array(substr($_GET['qry'],0,1), array('a','e','i','o','u')) ? 'an' 'a'; ?>

If I also tried the IF / ELSE statement, which led to the same result.

<?php if(in_array(substr($_GET['qry'],0,1), array('a','e','i','o','u'))):'an':'a'; ?>

I am sure that I am missing something simple, most likely due to my attempt to insert this fragment among the standard HTML text; can anyone identify my error (s)?

This is the error I am returning:

Parse error: parse error in C: \ Program Files (x86) \ Apache Software Foundation \ Apache2.2 \ htdocs \ testsite \ html \ page.html.php on line 117

Thank!

+4
source share
2 answers
<?php in_array(substr($_GET['qry'],0,1), array('a','e','i','o','u')) ? 'an' : 'a'; ?>

Removal if(). Ternary operators do not use if()what they are intended to conditionally check everything at once.

Link:


Footnotes: (OP)

"Excellent! Also, for those who are trying to use this in the future, I forgot to repeat the statement (which is easy to fix ... <?php echo ...If you add the above as an answer, I will definitely mark it as such. Thank you so much for your help! "

+6
source

The ternary operator syntax is:

($conditions) ? "if condition is true" : "if condition is false";

: . : . : http://php.net/manual/en/language.operators.comparison.php ( )

0

All Articles