howie2009
05-20-2011, 10:39 PM
Hi Guys,
ExpressionEngine cms uses url segment variables:
http://expressionengine.com/user_guide/templates/globals/url_segments.html
so just wondering how to do the following with raw php:
If i have 2 urls for demo purposes:
www.mysite.com/animals/dogs/terrier
www.mysite.com/animals/cats/blackcat
where
segment1 = animals
segment2 = dogs
and segment3 = terrier
I'd like to be able to use raw php in my templates such that:
if segment1= animals
show this html/php code
else
show this other html/php code
or
if segment3= blackcat
show this html/php code
else
show this other html/php code
and so on for upto 5 segments or more.
I'm phrasing it very basically out of my own PHP newbie ignorance but hopefully someone will know the code I'm after. The segments will relate to the url in the browser as opposed to some fixed url like the samples above.
Thanks
Googling revealed 2 examples which I fused together so syntax probably totally wrong to try and explain. (may help}
<?php
$uri = $_SERVER['REQUEST_URI'];
$segment = explode("/", $uri);
$uri_3 = $segment[3];
if ($segment[3]=="blackcat")
echo "Have a nice weekend!"; //i want to echo a chunk of html code though
else
echo "Have a nice day!"; //i want to echo a chunk of html code though
if ($segment[1]=="animals")
echo "Have a nicer weekend!"; //i want to echo a chunk of html code though
else
echo "Have a nicer day!"; //i want to echo a chunk of html code though
?>
ExpressionEngine cms uses url segment variables:
http://expressionengine.com/user_guide/templates/globals/url_segments.html
so just wondering how to do the following with raw php:
If i have 2 urls for demo purposes:
www.mysite.com/animals/dogs/terrier
www.mysite.com/animals/cats/blackcat
where
segment1 = animals
segment2 = dogs
and segment3 = terrier
I'd like to be able to use raw php in my templates such that:
if segment1= animals
show this html/php code
else
show this other html/php code
or
if segment3= blackcat
show this html/php code
else
show this other html/php code
and so on for upto 5 segments or more.
I'm phrasing it very basically out of my own PHP newbie ignorance but hopefully someone will know the code I'm after. The segments will relate to the url in the browser as opposed to some fixed url like the samples above.
Thanks
Googling revealed 2 examples which I fused together so syntax probably totally wrong to try and explain. (may help}
<?php
$uri = $_SERVER['REQUEST_URI'];
$segment = explode("/", $uri);
$uri_3 = $segment[3];
if ($segment[3]=="blackcat")
echo "Have a nice weekend!"; //i want to echo a chunk of html code though
else
echo "Have a nice day!"; //i want to echo a chunk of html code though
if ($segment[1]=="animals")
echo "Have a nicer weekend!"; //i want to echo a chunk of html code though
else
echo "Have a nicer day!"; //i want to echo a chunk of html code though
?>