E
E
Eugene2021-06-09 10:40:18
PHP
Eugene, 2021-06-09 10:40:18

Generating 'title' via $_GET request?

I want to generate 'title' via $_GET request: How to do, if $street data exists, then add the word STREET. And if the parameter then add the word REFERENCE. But if there is no "street" value, then the word street is not displayed. I output the title like this:
$street = $_GET["street"];
$orient = $_GET["orient"];

'title' => $street. "". $orient

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis, 2021-06-09
@jeka12345

$street = htmlspecialchars($_GET["street"] ?? '');
$orient = htmlspecialchars($_GET["orient"] ?? '');


return [
'title' => trim ( ($street ? "Улица $street" : "") .  " " . ($orient ? "Ориентир $orient" : "") ),
];

D
Dmitry Markov, 2021-06-09
@En-Tilza

The ternary operator will help you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question