Thomshaw Posted April 17, 2012 Share Posted April 17, 2012 Hi all, Relitively new to PHP but am trying to code a site that dynamically creates urls using Joomla CMS. Basically I'd like a div to show on pages' url starts /component/.... but hide it if not. The urls of the pages on which the div is to be hidden start /index.php?. I've tried <?php if (strpos($_SERVER['REQUEST_URI'], 'component') > 0) { echo '<div id=\"stuffdiv\">stuff</script></div>';} ?> only issue is... its always fasle hence the div never shows. If i replace > with >= its always true, and appears on all pages, even those not containing 'component'... Can someone tell me if this should work or if Im being really stupid? Thanks in advance! Tom Quote Link to comment Share on other sites More sharing options...
Thomshaw Posted April 17, 2012 Author Share Posted April 17, 2012 Sorry, dont know how to edit post the </script> isnt there, is a reference to whats in the div i copied accross! Quote Link to comment Share on other sites More sharing options...
cpd Posted April 17, 2012 Share Posted April 17, 2012 if (strpos($_SERVER['REQUEST_URI'], 'component') !== false) { echo '<div id="stuffdiv">stuff</script></div>'; // You do not need to escape the double-quotes unless you create the string using double quotes. } Quote Link to comment Share on other sites More sharing options...
Thomshaw Posted April 17, 2012 Author Share Posted April 17, 2012 Amazing CPD thanks so much, worked with a little jiggery pokery <?php if (strpos($_SERVER['REQUEST_URI'], 'foo') == false) { echo '<div id="stuffdiv">stuff</div>';} ?> where foo appears in the url of the page on which the div should be hidden Again, can't thank you enough! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.