I'm using the following code to echo a part of a URL and my dynamic URL now looks like this.
https://example.test/test.php?name=living-room
But the condition is that, it will only echo if the name part of the URL is in my array.
$array = array('kitchen', 'bedroom', 'living room', 'dining room');
if (in_array($_GET['name'], $array))
{echo $_GET['name'];}
else {header("HTTP/1.0 404 Not Found");}
What I'm trying to do is treat the - in URL's name part as spaces.
For example, living-room should be equal to living room in my array and it should echo the value in my array (living room) instead of (living-room).
- So if the URL's value is
living-room, we check the array and sinceliving roomexists in the arrayliving roomwill get echoed. - In the same way as before, if the URL's value is
dining-room, sincedining roomexists in my array,dining roomwill get echoed.
I'm having a hard time finding the correct logic to this.