Jump to content

Archived

This topic is now archived and is closed to further replies.

saiko

use variables in html without php brackets

Recommended Posts

EDIT: topic title supose to say " use variables in html WITHOUT php brackets"

how can i use variables in html without having to do the php brackets: <?php $variable; ?>

??

Share this post


Link to post
Share on other sites
A couple of ways that you can use.
[b]1) Put your html in print statements:[/b]
[code]
   print "<htm>" .
        "<head><title> $pageTitle </title></head>" .
        "<body>"; /* etc */
[/code]

[b]2) Use place holders and then parse your text.[/b]
[code]$html = <<< HTML
<h2>[TITLE]<h2>
Posted [DATE] by [AUTHOR]
HTML;

$search = array($postTitle, $postDate, $postAuthor);
$repace = array('[TITLE]', '[DATE]', '[AUTHOR]');

$html = str_replace($search,$replace,$html);
print $html;
[/code]

The good thing about the second method is that you can read that from a file. I typically have html files with variable place holders for different sections of the page (header, footer, navbar, etc). The best thing about this method is that you are separating your content from your code. If you do it properly, you can adjust one without messing up the other. Also works well when you start working with someone who has little or no programming knowledge.

Share this post


Link to post
Share on other sites
You can't...

PHP is a scripting language, not a mind reader..

What if you wanted to make a HTML page.. that said IF MY GRANDMA GOT CAUGHT IN A STORM, I WOULDNT KNOW WHAT TO DO..

See how in that sentene alone, you have a few reserved words.. imagine PHP trying to process all of that and determined if it was supposed to be code or not. That'd be one slow page, wouldn't it?

SO. You're stuck with the <?, <%, or however else you call it.

Share this post


Link to post
Share on other sites
your sorta on the rite track.

this is also part of my skining system.

it gets the file site_head.php now i dont want the admin having to put <?php echo $variable;?> on everthing so i was thinking i could use some other way.

things i want are things such as the "images path" is stored in the variable "$images_path"

so if it was set to "skins/1/images" then i want to add that to the start of all there images links

eg. they have "images_01.jpg" i want it to be changed to "skins/1/images/images/images_01.jpg"

so wat im trying to say is there a way i can find and replace the code in the file.

or is there a way i can use another method of echoing the variables other then using the <?php echo $variable; ?>

like with ipb how they do <% TITLE %> ---- NOTE: i dont have a clue how to do this ------

hope you can understand :D

Share this post


Link to post
Share on other sites

×

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.