Dragen Posted July 29, 2007 Share Posted July 29, 2007 I'm not sure if this can be done, but I think I might have seen it before.. can't remember. I'm trying to get my php pages to parse php within HTML, instead of php brackets. Basically instead of having: lets echo a variable/constant: <?php echo $somevariable . ' or ' . SOMECONSTANT; ?> I want to use somhing like: lets echo a variable/constant: {$somevariable} or {SOMECONSTANT} Is this at all possible? I'm not wanting to do anything more difficult than echoing simple variables or constants.. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 29, 2007 Share Posted July 29, 2007 you can do <?php $myname = "bob"; <html> Hello World My name is: <?php echo $myname;?><br/> outputs Hello World My name is: bob is that what you saying. The doc would have to be a .php file instead you rewrote .htaccess to allow .html pages to phrase as .php Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 29, 2007 Share Posted July 29, 2007 Not possible unless everything i've ever read about php tags was rubbish Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 29, 2007 Share Posted July 29, 2007 I see what you saying. Why would the proper tagging for php (<?php ?>) be a problem? Its phrased PRE HYPERTEXT i.e user doesn't see it. Quote Link to comment Share on other sites More sharing options...
Dragen Posted July 29, 2007 Author Share Posted July 29, 2007 <?php $myname = "bob"; <html> Hello World My name is: <?php echo $myname;?><br/> Thanks, I know that would work, but I'm trying to find a way of working it without the need of using <?php echo; ?> Maybe there's some way of setting up a page to parse all text between {} as php, instead of html. It's for a script I'm working on that is going to be used by different people, who probably wont know php, but may have basic knowledge of html, so instead of having to put in lots of echoes every time they want to output a variable I wanted it to be as simple as entering the variable name.. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 29, 2007 Share Posted July 29, 2007 If you are writing a script for someone who doesn't know scripting you should look into using a database to store data and then recall it. Also look into smarties or phpBB it lets you create psedo tags that interpret however you want, but not in the raw script, but in a text box sorta like saying colon left bracket and having an emodicon show up. Quote Link to comment Share on other sites More sharing options...
corbin Posted July 29, 2007 Share Posted July 29, 2007 You could do something like this: $html = '<h1>{$header}</h1><a href="{$link}">{$name}</a>'; $tpl = array('header' => 'This is a header!', 'link' => 'http://google.com/', 'name' => 'Google'); foreach($tpl as $k => $v) { $html = str_replace('{$' . $k . '}', $v); } echo $html; //it would echo: //<h1>This is a header</h1><a href="http://google.com/">Google</a> Quote Link to comment Share on other sites More sharing options...
Dragen Posted July 29, 2007 Author Share Posted July 29, 2007 Also look into smarties or phpBB it lets you create psedo tags that interpret however you want, but not in the raw script, but in a text box sorta like saying colon left bracket and having an emodicon show up. ah cooldude! I think you've got it.. must've been phpbb where I'd seen it before.. I'm trying to create a templating system, I guess pseudo tags or similar is what I need to implement... could you give me any advice on how to do something like that? or any links would be great! Thanks Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 29, 2007 Share Posted July 29, 2007 download bb and read through it I think you can download just the smarties libarry/write your own. Just use mysql and form input like a forumn idea, but for content area and you can make a few custom tags like Date or name {date} {name} Quote Link to comment Share on other sites More sharing options...
Dragen Posted July 29, 2007 Author Share Posted July 29, 2007 okay, I see how that works if all of the text is stored in the database, such as forum posts or news articles etc.. using a simple preg_replace or similar.. But what I'm looking for is if they enter the pseudo text in a template file. for example.. (I've just searched through my phpbb download) in index_body.tpl for the default template it's got this: <td><span class="gensmall">{L_NEW_POSTS}</span></td> and the {L_NEW_POSTS} is parsed as php instead of html. EDIT: just had a closer look at phpbb and I think it's using classes.. which is something I've never understood before. Does anyone know any good sites about classes? I've tried searching google and php.net, but couldn't find much.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.