Jump to content

use variables in html without php brackets


saiko

Recommended Posts

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.
Link to comment
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.
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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