Jump to content


Photo

use variables in html without php brackets


  • Please log in to reply
4 replies to this topic

#1 saiko

saiko
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 15 March 2006 - 07:10 AM

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; ?>

??

#2 greycap

greycap
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 15 March 2006 - 08:23 AM

A couple of ways that you can use.
1) Put your html in print statements:
   print "<htm>" . 
        "<head><title> $pageTitle </title></head>" . 
        "<body>"; /* etc */

2) Use place holders and then parse your text.
$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;

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.

#3 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 15 March 2006 - 08:40 AM

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.

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#4 saiko

saiko
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 15 March 2006 - 08:50 AM

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

#5 saiko

saiko
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 15 March 2006 - 11:05 PM

*bump*




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users