PcGeniusProductions Posted January 26, 2008 Share Posted January 26, 2008 Hi there. Please don't laugh when I ask for help on something this simple, but i really have no clue. I have tried, and kept recieving errors. This code Displays "Site Name: Page Name" I want it to display "Page Name | Site Name" Here is the code: <title>".SITENAME.(defined("e_PAGETITLE") ? ": ".e_PAGETITLE : (defined("PAGE_NAME") ? ": ".PAGE_NAME : ""))."</title>\n"; Can someone help me please? Thanks in Advance. Quote Link to comment https://forums.phpfreaks.com/topic/87943-re-order-this-line/ Share on other sites More sharing options...
Lumio Posted January 26, 2008 Share Posted January 26, 2008 Hard one: echo "<title>".(defined("e_PAGETITLE") ? e_PAGETITLE.' | ' : (defined("PAGE_NAME") ? PAGE_NAME.' | ' : "")).SITENAME."</title>\n"; Easy one: <?php $_page = ''; //defined variable defined("PAGE_NAME") && $_page = PAGE_NAME; defined("e_PAGETITLE") && $_page = e_PAGETITLE; ($_page != '') && $_page .= ' | '; //if variable is filled echo "<title>".$_page.SITENAME."</title>\n"; ?> Also it isn't recommended to ouput html-code with php. Quote Link to comment https://forums.phpfreaks.com/topic/87943-re-order-this-line/#findComment-450061 Share on other sites More sharing options...
laffin Posted January 26, 2008 Share Posted January 26, 2008 for some reason that code dun look right. defined("PAGE_NAME") && $_page = PAGE_NAME; defined("e_PAGETITLE") && $_page = e_PAGETITLE; ($_page != '') && $_page .= ' | '; //if variable is filled since there is no if structure testiing the expression. nor is it a valid assignment operation. and the one before echo "<title>".(defined("e_PAGETITLE") ? e_PAGETITLE.' | ' : (defined("PAGE_NAME") ? PAGE_NAME.' | ' : "")).SITENAME."</title>\n"; looks syntatically correct. and the expression is not mixing PHP & HTML, they are clearly seperated anyways to answer the question all u have to do is break down the string into it's different components echo "<title>". SITENAME. ( defined("e_PAGETITLE") ? e_PAGETITLE . ' | ' : ( defined("PAGE_NAME") ? PAGE_NAME.' | ' : "" ) ). "</title>\n"; once u have the different components of the string broken down ya can move the various pieces around echo "<title>". ( defined("e_PAGETITLE") ? e_PAGETITLE . ' | ' : ( defined("PAGE_NAME") ? PAGE_NAME.' | ' : "" ) ). SITENAME. "</title>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/87943-re-order-this-line/#findComment-450070 Share on other sites More sharing options...
Lumio Posted January 27, 2008 Share Posted January 27, 2008 laffin... where can you see, that php and html is NOT mixed? He is outputing it with php. Also learn PHP defined("PAGE_NAME") && $_page = PAGE_NAME; defined("e_PAGETITLE") && $_page = e_PAGETITLE; ($_page != '') && $_page .= ' | '; //if variable is filled That works. Quote Link to comment https://forums.phpfreaks.com/topic/87943-re-order-this-line/#findComment-450350 Share on other sites More sharing options...
laffin Posted January 27, 2008 Share Posted January 27, 2008 Simple php code will not work in a HTML setting. and HTML will not work in a php setting. Thus the php tags that encases/seperates php code from html code. php can output html, it's the primary use. that's a bizarre trick u have going there, never seen it before. Quote Link to comment https://forums.phpfreaks.com/topic/87943-re-order-this-line/#findComment-450358 Share on other sites More sharing options...
Lumio Posted January 27, 2008 Share Posted January 27, 2008 Simple php code will not work in a HTML setting. and HTML will not work in a php setting. Thus the php tags that encases/seperates php code from html code. php can output html, it's the primary use. For sure, but it makes a difference if you write <?php //your code ?><html> <head> <title><?php $title = md5(rand(0,1)); echo $title; ?></title> </head> <body>You are here: <?php echo $title; ?></body> </html> or output every html-tag with php. Also it's a little messy because of quotes: <?php echo "<b style=\"foo\">$bar</b>"; ?> it makes more sense to write it like <b style="foo"><php echo $bar ?></b> that's a bizarre trick u have going there, never seen it before. Why is it bizarre? It is valid PHP defined("PAGE_NAME") returns true if PAGE_NAME is defined. So the code after && (AND) is executed. If defined("PAGE_NAME") returns false it leaves it out. That works only if you only set variables or call functions. It won't work with return So defined("PAGE_NAME") && return 'works'; won't work. You have to use if (defined("PAGE_NAME")) return 'works'; Quote Link to comment https://forums.phpfreaks.com/topic/87943-re-order-this-line/#findComment-450367 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.