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.. Link to comment https://forums.phpfreaks.com/topic/62357-parse-php-through-html/ 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 Link to comment https://forums.phpfreaks.com/topic/62357-parse-php-through-html/#findComment-310306 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 Link to comment https://forums.phpfreaks.com/topic/62357-parse-php-through-html/#findComment-310308 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. Link to comment https://forums.phpfreaks.com/topic/62357-parse-php-through-html/#findComment-310310 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.. Link to comment https://forums.phpfreaks.com/topic/62357-parse-php-through-html/#findComment-310314 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. Link to comment https://forums.phpfreaks.com/topic/62357-parse-php-through-html/#findComment-310316 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> Link to comment https://forums.phpfreaks.com/topic/62357-parse-php-through-html/#findComment-310317 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 Link to comment https://forums.phpfreaks.com/topic/62357-parse-php-through-html/#findComment-310327 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} Link to comment https://forums.phpfreaks.com/topic/62357-parse-php-through-html/#findComment-310334 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.. Link to comment https://forums.phpfreaks.com/topic/62357-parse-php-through-html/#findComment-310349 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.