Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change HTML title in PHP without breaking the XHTML markup validation?
    primarykey
    data
    text
    <p>Here is the structure of the web site:</p> <p><strong>PHP index file</strong></p> <pre><code>//my class for analyzing the PHP query $parameter = new LoadParameters(); //what this does is it accesses the database //and according to the query, figures out what should be //loaded on the page //some of the things it sets are: // $parameter-&gt;design - PHP file which contains the design // HTML code of the page // $parameter-&gt;content - Different PHP file which should be loaded // inside the design file $parameter-&gt;mysqlGetInfo($_SERVER['QUERY_STRING']); //load the design file include($parameter-&gt;design); </code></pre> <p><strong>PHP design file</strong></p> <p>Just the generic structure. Obviously it has a lot more design elements.</p> <pre><code>&lt;html&gt; &lt;head&gt; ... &lt;/head&gt; &lt;body&gt; &lt;?php //this loads the content into the design page include($parameter-&gt;content); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>Question</strong></p> <p>So here is the problem I experience. The <code>$parameter-&gt;content</code> file is a dynamic PHP file, meaning the content also changes according to the query.</p> <p>For instance if I have a image pages with queries like <code>?img=1</code> and <code>?img=2</code>, my <code>LoadParameter</code> class will only look at the <code>img</code> part of the query and will know that the content of the page should be <code>image.php</code>. <code>image.php</code> however will look at the query again and figure out exactly what image to load.</p> <p>This causes issues for me because I want to have a different <code>&lt;title&gt;&lt;/title&gt;</code> for different images. So my solution was just to set the <code>&lt;title&gt;&lt;/title&gt;</code> element in the content page. This works but it breaks the XHTML markup validation at <a href="http://validator.w3.org/" rel="nofollow">W3C</a> because it makes the structure of the site to be the following:</p> <pre><code>&lt;html&gt; &lt;head&gt; ... &lt;/head&gt; &lt;body&gt; ... &lt;title&gt;sometitle&lt;/title&gt; ... &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And having <code>&lt;title&gt;&lt;/title&gt;</code> within <code>&lt;body&gt;&lt;/body&gt;</code> is not allowed.</p> <p>So how can I change the title without breaking the XHTML markup validation?</p> <p><em><strong>Note</em></strong>: I can't use javascript because then Search engines would not be able to see the title of the page. I need to do it directly in PHP.</p> <p>Thanx in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload