Jump to content

john010117

Members
  • Posts

    492
  • Joined

  • Last visited

    Never

Posts posted by john010117

  1. Hello.

     

    I have a simple 2-column full-CSS layout (meaning: no tables). While putting the borders in, I have noticed that they do not show to the extent of the parent div. Let me show you what I mean:

     

    #overall_div {
        width: 100%;
    }
    
    #column_1 {
        width: 25%;
        float: left;
        border-right: 1px solid #c2c2c2;
    }
    
    #column_2 {
        width: 75%;
        float: left;
    }
    
    <div id="overall_div">
        <div id="column_1">
            ...random content...
        </div>
        <div id="column_2">
            ...random content...
        </div>
    </div>

     

    Please note that that is the simplified code that I'm working with.

     

    Anyways, if column #1 is "taller" than column #2, than the border will show fine. However, if column #2 is taller than column #1, the border only reaches up to the point where column #1's content ends. Now, I'm aware that CSS is supposed to do this, but is there any workaround?

  2. Ok, I tried that method, but that outputted no difference. To make sure, I've echo'ed the value of $IM within the loop, and it shows what it's supposed to show. Here's the updated code:

     

    <?php
    class template
    {
    var $template_root = './template';
    var $output;
    
    function _include_template($filename)
    {
    	ob_start();
    	include($this->template_root . '/' . $filename);
    	$content = ob_get_contents();
    	ob_end_clean();
    	return $content;
    }
    
    function compile($filename)
    {
    	$this->output = @file_get_contents($this->template_root . '/' . $filename);
    
    	preg_match_all('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\./]+) -->#', $this->output, $include_matches);
    
    	if(!empty($include_matches[1]))
    	{
    		foreach($include_matches[1] as $IM)
    		{
    			$this->output = preg_replace('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\./]+) -->#', $this->_include_template($IM), $this->output);
    		}
    	}
    	echo $this->display();
    }
    
    function display()
    {
    	return $this->output;
    }
    }
    ?>
    

     

    I'm just guessing, but could the problem lie in the _include_template() function with the output buffering?

  3. explain !

    However, if I include two or more files, the first file that was included in the template keeps on getting included over and over again.

     

    What I mean is this:

     

    Let's say I had the template file "index_body.html" (called from index.php). Then, in that template file, I include "index_2.html". So far, so good. But, if I include "index_3.html" or any other file below the first include statement, only "index_2.html" shows up within "index_body.html". That happens  the number of include statements (stated in index_body.html) times.

  4. I have managed to build a small template class that can so far parse template variables. Now, to move one step further, I have begun to put in a template include part (includes separate templates within a template file). Here's what I have so far (only the include parts are shown):

     

    <?php
    class template
    {
    var $template_root = './template';
    var $output;
    
    function _include_template($filename)
    {
    	ob_start();
    	include($this->template_root . '/' . $filename);
    	$content = ob_get_contents();
    	ob_end_clean();
    	return $content;
    }
    
    function compile($filename)
    {
    	$this->output = @file_get_contents($this->template_root . '/' . $filename);
    
    	// Locates all the include statements (looks like: <!-- INCLUDE some_file.html -->)
    	preg_match_all('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\./]+) -->#', $this->output, $include_matches);
    
    	if(!empty($include_matches[1]))
    	{
    		for($i = 0, $size = sizeof($include_matches[1]); $i < $size; $i++)
    		{
    			$this->output = preg_replace('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\./]+) -->#', $this->_include_template($include_matches[1][0]), $this->output);
    			array_shift($include_matches[1]);
    		}
    	}
    	echo $this->display();
    }
    
    function display()
    {
    	return $this->output;
    }
    }
    ?>

     

    If I include one file in a template file, the file shows up fine. However, if I include two or more files, the first file that was included in the template keeps on getting included over and over again. Does anyone see a problem with this code? Help will be much appreciated.

  5. I already have a method of calculating the age by a given birthdate, but I have no idea how to do that in reverse. Here's my method on calculating the age by given birthdate:

     

    <?php
    function calculate_age($month, $day, $year) {
    global $month, $day, $year;
    $time = time();
    $new_date = mktime(0, 0, 0, $month, $day, $year);
    $age = ($new_date < 0) ? ($time + ($new_date * -1)) : $time - $new_date;
    $year = 60 * 60 * 24 * 365;
    $return_age = $age / $year;
    
    return floor($return_age);
    }
    ?>
    

     

    But my question is how do you reverse this process so it outputs the birthdate?

×
×
  • 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.