Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/87943-re-order-this-line/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/87943-re-order-this-line/#findComment-450061
Share on other sites

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";

 

Link to comment
https://forums.phpfreaks.com/topic/87943-re-order-this-line/#findComment-450070
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/87943-re-order-this-line/#findComment-450350
Share on other sites

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/87943-re-order-this-line/#findComment-450358
Share on other sites

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';

Link to comment
https://forums.phpfreaks.com/topic/87943-re-order-this-line/#findComment-450367
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.