Guest Posted September 2, 2007 Share Posted September 2, 2007 Hey, I've built a small Template system that parses ASP.NET-like tags in HTML files and makes them useful in PHP. So my template file has bits like so: <div id="intro"> <h2>Videos</h2> <p>Make sure to check out our new <a href="#">Media Service</a></strong></p> <p> <php:region id="intro_main"> Welcome to the RDKLeague Videos Portal, the home of Halo: CE & Halo 2 Montages, Gameplays and Movies. Please keep in mind that this project is in beta form and it is not fully completed. </php:region> <php:region id="intro_archive" visibility="false"> This is a collection of all our videos to date--enjoy. </php:region> <php:region id="intro_top"> These videos are our best and brightest. Want to take part? View a video and vote today! </php:region> </div> Ok, so, looking at the above, the SECOND php:region has a second attribute, which is visibility="false" Alright, with some nifty regex, I've managed to extract the attributes and have a TemplateRegion object sort them out. All is good. Except when it comes down to using that value. Once that value is extracted from the HTML, it ends up as the string 'false' -- which to all boolean tests, comes back as the boolean true. I've tried type casting the string--that didn't work. I've also wanted to (when it checks for whether $visibility == false, for it to check for the string value 'false' as well, but that feels a little messy, so I'm looking for other options). I've thought about using eval('false'), but I'm hesitant to rely on eval. And I just can't think of anything at the moment, hopefully there are some bright minds out there that can fill in the gap. Any suggestions? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/67634-converting-false-to-false/ Share on other sites More sharing options...
Barand Posted September 2, 2007 Share Posted September 2, 2007 Does it help changing visibility="false" to visibility="" Quote Link to comment https://forums.phpfreaks.com/topic/67634-converting-false-to-false/#findComment-339759 Share on other sites More sharing options...
Guest Posted September 2, 2007 Share Posted September 2, 2007 If you mean within the html template, no, if an attribute is empty (or non-existant), the TemplateRegion object will use (boolean) true as its default (unless another default is specified). If you mean convert the string 'false' to '' to make it evaluate to false: I completely forgot about that, this worked perfectly. <mumbling> However, the next morning, I decided to make the attribute visibility less strict, allowing for on/off, yes/no, true/false -- all of which evaluate to strings. Because the on/yes/true side as strings will evaluate to true, I only really needed to take care of the off/no/false side. So I have it intercepting the attribute right after parsing, to change any values of 'off', 'no' or 'false' to a boolean false. </mumbling> Hopefully, that made sense. If not, thanks for the help anyway! Quote Link to comment https://forums.phpfreaks.com/topic/67634-converting-false-to-false/#findComment-340037 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.