FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


php html tags





garionw
What I want is a bit confusing, you'll know what I mean if you've had any experience with phpbb themes.

What I would like is to know how to set it up so that if I was to enter {header} in my HTML code it would come up with a certain function. Hopefully this table can explain it more:

{connect} = mysql_connect("localhost", "root", "") or die(mysql_error());
{header} = include ('head.inc.php');
{footer} = include ('foot.inc.php');


Thanks in Advance, Garion
Philip
not enough clear,
pleasee add more information about those question Smile
garionw
never mind, I think its called: str_replace. If this is true can someone give me a quick example on hot to use it
Agent ME
Here's an idea-

Code:

<?php
$header = (do something here to give header a value - take something from an MySQL database or file);
$footer = (ditto);
?>
<html>
<head><title>Test Page</title></head>
<body>
<?php echo $header; ?>
<p>Lol there's a header above this text!</p>
<?php echo $footer; ?>
</body>
</html>
garionw
no, I'm sure its str_replace - its for some blogging software im hoping to make and to make it easier for people I really want it to be like {header}...
garionw
Is anyone able to help me pelase
jeremyyak
It's called a macro, it works the same was as BBCode.

It works like this:
Code:

<html>
<head>
%header%
</head>
<body>
%wrapper%
%contents%
%copyright%
</body>
</html>


And the macro works like this:
Code:

<?php
$header=file_get_contents("./pages/heading.php");
$wrap=file_get_contents("./pages/wrapper.php");
$copy=file_get_contents("./pages/copyrightphp");
$contents="Blah blah blah blah. Words go here. Blah blah blah";
$html = str_ireplace ("%header%", $header, $html);
$html = str_ireplace ("%wrapper%", $wrap, $html);
$html = str_ireplace ("%contents%", $contents, $html);
$html = str_ireplace ("%copyright%", $copy, $html);
?>


I don't know the exact method of doing it, but theres an example.
~Jeremy~
garionw
Thanks for that, Now I need some help implententing it. Heres what I have so far:

Code:

<?php

$contents="Blah blah blah blah. Words go here. Blah blah blah";

$html = str_ireplace("%contents%", $contents, $html);
?>

<html>
<head>

</head>
<body>

%contents%

</body>
</html>


And when I test that in localhost I get this error message:
Code:

Fatal error: Call to undefined function: str_ireplace() in c:\program files\easyphp1-8\www\dos\test.php on line 5
Aredon
The function is not available 'til PHP 5.

One of the comments added to the function at PHP.net give a backdoor function definition for it:
Code:

<?php
if(!function_exists('str_ireplace')) {
   function str_ireplace($search, $replacement, $string){
       $delimiters = array(1,2,3,4,5,6,7,8,14,15,16,17,18,19,20,21,22,23,24,25,
       26,27,28,29,30,31,33,247,215,191,190,189,188,187,186,
       185,184,183,182,180,177,176,175,174,173,172,171,169,
       168,167,166,165,164,163,162,161,157,155,153,152,151,
       150,149,148,147,146,145,144,143,141,139,137,136,135,
       134,133,132,130,129,128,127,126,125,124,123,96,95,94,
       63,62,61,60,59,58,47,46,45,44,38,37,36,35,34);
       foreach ($delimiters as $d) {
           if (strpos($string, chr($d))===false){
               $delimiter = chr($d);
               break;
           }
       }
       if (!empty($delimiter)) {
           return preg_replace($delimiter.quotemeta($search).$delimiter.'i', $replacement, $string);
       }
       else {
           trigger_error('Homemade str_ireplace could not find a proper delimiter.', E_USER_ERROR);
       }
   }
}
?>


http://us2.php.net/manual/en/function.str-ireplace.php
snowboardalliance
garionw wrote:
Thanks for that, Now I need some help implententing it. Heres what I have so far:

Code:

<?php

$contents="Blah blah blah blah. Words go here. Blah blah blah";

$html = str_ireplace("%contents%", $contents, $html);
?>

<html>
<head>

</head>
<body>

%contents%

</body>
</html>


And when I test that in localhost I get this error message:
Code:

Fatal error: Call to undefined function: str_ireplace() in c:\program files\easyphp1-8\www\dos\test.php on line 5


Also, the $html variable needs to be a variable with the contents of a file basically.
So you have a file that is
Code:

<html>
<head>

</head>
<body>

%contents%

</body>
</html>


You open it with php, into a variable and do the str_replace. Then you can just output this.

If you need more info on this subject, try googling "php template system" without the quotes. That may be helpful.
Related topics
PHP Toturail
problems for indexing php pages in google.
php/HTML pages question
neep help making email form that accepts html tags
How to upload a file via html-form and php?
How to change extension php to html but the php script still
Help with php and java script
PHP Wordcut
how do you Exclude Certain html tags?
Web form to save HTML table as spreadsheet
Wanting a PHP input security script: up to 1200frih$!
The best php and html editor?
PHP inside HTML tags?
<?php ?> Tags
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.