qrahaman Posted December 19, 2011 Share Posted December 19, 2011 Hello, I'm having a bit of trouble with the following: <?php echo htmlentities('<img src="<?php bloginfo('template_directory');?>/images/my-image.png" / rel="nofollow">'); ?> As you can see, I am trying to use php to call the template directory but it isn't being recognized as a php statement. I'm new to php and I'm pretty certain my syntax is not right. Can someone provide a bit of guidance? Thank you. Quint Quote Link to comment https://forums.phpfreaks.com/topic/253490-when-to-close-and-open-the-php-tags/ Share on other sites More sharing options...
ManiacDan Posted December 19, 2011 Share Posted December 19, 2011 You cannot "nest" PHP tags. You can only open PHP tags if the previous one has been closed. You want to research string concatenation. This is correct: <?php echo htmlentities('<img src="' . bloginfo('template_directory') . '/images/my-image.png" rel="nofollow" />'); ?> -Dan Quote Link to comment https://forums.phpfreaks.com/topic/253490-when-to-close-and-open-the-php-tags/#findComment-1299404 Share on other sites More sharing options...
Psycho Posted December 19, 2011 Share Posted December 19, 2011 I'd also add that trying to do too many things in one line of code can be confusing to the point of any possible efficiencies are outweighed by the inability to read/manage the code. I would probably do somethign such as: <?php $blogInfo = bloginfo('template_directory'); echo htmlentities('<img src="' . $blogInfo . '/images/my-image.png" / rel="nofollow">'); ?> Although, you do realize that the above will not be a hyperlink because of the htmlentities, right? Quote Link to comment https://forums.phpfreaks.com/topic/253490-when-to-close-and-open-the-php-tags/#findComment-1299452 Share on other sites More sharing options...
ManiacDan Posted December 19, 2011 Share Posted December 19, 2011 Note that your HTML tag had a random / in the middle for no reason. I fixed it in my code (moved it to the end) but mj did not. Be careful with the syntax. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/253490-when-to-close-and-open-the-php-tags/#findComment-1299462 Share on other sites More sharing options...
qrahaman Posted December 19, 2011 Author Share Posted December 19, 2011 Awesome question! I'm sure you know what the answer is. And the difference comes down to bloginfo() vs get_bloginfo(). Thank you so much for your help! P.S. Thanks Dan for the clarification. Quote Link to comment https://forums.phpfreaks.com/topic/253490-when-to-close-and-open-the-php-tags/#findComment-1299470 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.