First time on HTML Parsing - Need some help!

Hi. Today I want to do a php page that render part of my html code. Let me explain with some code…

I have a first part of a HTML page (have head tags, css code and part of the body)
a second HTML page (have multiple content, I explain this later)
and a third HTML page (this one have the last tags (such as and similar)

The second HTML page derives from a PHP script. This script has multiple HTML codes that run when I call them with $_GET variable.

Example of the second page:
[php]<?php
//loads the first part of the HTML page
require_once(“partOne.html”);

switch ($_GET[“contentName”]) {
case “welcome”:
// reads the content with ID “welcome” [I don’t know how to to that]
break;
case “goodbye”:
// reads the content with ID “goodbye” [Same thing here!]
break;
}

//loads the third part of the HTML page
require_once(“endpage.html”);
?>

// ...code...
// ...code...
[/php]

So I want to write on the address bar “page.php?contentName=welcome” and see all the page without the goodbye content and vice versa. But I don’t know how to do that. In some forums they said to use “HTML Parser”, could you give me sample codes to understand how to use that? Thanks.

I’m not sure if this is what you are looking for or not, but try this:

[code]

Welcome/Goodbye Test <?php $welcome = $goodbye = 'display: none;'; switch ($_GET["contentName"]) { case "welcome": $welcome = ''; break; case "goodbye": $goodbye = ''; break; } ?> #welcome{ <?php echo $welcome; ?> } #goodbye{ <?php echo $goodbye; ?> }
Welcome to the page...
Thanks for visiting...
[/code]

I would try to avoid splitting the html opening tags into one file and the closing tags into another. This could become very difficult to manage down the road and seems to be unnecessary - if I understand what you are trying to do correctly.

What the above does is to use CSS to only display the div id that is called for in the url. If you had a number of choices, instead of just welcome and goodbye, I would use arrays instead and replace the switch with an embedded if…then inside a foreach loop.

There are several other ways of tackling the issue, many of which may be better solutions depending on what the actual code looks like and is doing. For example, creating a welcome.html file and a goodbye.html file and include them using your php switch.

Please let me know if this doesn’t work or if I have misunderstood what you are looking to do.

Sorry.

I just realized that the ending tags are missing from the example code I posted.

</body>
</html>

Yep, that’s right. Thanks! :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service