Jump to content

Converting 'false' to false


Guest

Recommended Posts

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.

Link to comment
Share on other sites

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!

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.