Affiliate Programs
 
Search affiliate programs for: 
Affiliate Categories
» Affiliate Networks
» Ad Networks
» 2 Tier Programs
» Pay Per Sale
» Pay Per Lead
» Residual Income
» Datafeeds
» Multi Tier Programs
» Business Opps
» Other Programs

Newsletter
Get newly added affiliate programs by email. Enter your email here:
Article Categories
» Affiliate Marketing
» Business
» Ecommerce
» Hosting
» Marketing
» Sales
» Web Designing
» Webmasters
» SEO & Promotion
» Working At Home
» Other Articles
» Affiliate Glossary


Go Back   AffiliateSeeking Forum > Website Creation, Design & Maintenance > Programming > PHP

PHP Discuss about your PHP scripting issues or help others with their PHP scripting problems.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-06-2011, 08:12 AM
pottiq pottiq is offline
Junior Member
 
Join Date: Dec 2011
Posts: 2
pottiq is on a distinguished road
Default Creating a basic template engine

Hello everybody,
I've started to work on building a template engine for a website since I need to seperate the logical units from the graphical units and template engines such as Smarty and TBS are way too big for what I really need: a very basic, simple template engine which manage simple tasks such as value reference and conditions.

The value referencing has been quite easy, a simple str_replace would do the job correctly. Where it gets complicated is at the conditional management. I need it to make, for exemple:

Code:
[IF USER_STATUS_ADMIN]{SHOW_ADMIN_LINK}[ELSEIF USER_STATUS_WRITER]{SHOW_WRITER_LINK}[ELSEIF USER_STATUS_TESTER]{SHOW_TESTER_LINK}[ELSE]{SHOW_ALL_LINK}[/IF]
turn into:

Code:
if $user_status_admin {
echo $show_admin_link;
}elseif $user_status_writer{
echo $show_writer_link;
}elseif $user_status_tester{
echo $show_tester_link;
}else{
echo $show_all_link;
}
I must admit that I am quite rusted in PHP, so to reach this goal I first thought about using a regex to dispatch all my values... I used this regex:

Code:
/\[IF (.*?)\](.*?)(\[\/IF\]|\[ELSEIF (.*?)\](.*?)\[\/IF\])/i
Before long I realized that I could only retrieve a single ELSEIF value. So I went with a string scaning method using this code:

Code:
$str = '[IF USER_STATUS_ADMIN]{SHOW_ADMIN_LINK}[ELSEIF USER_STATUS_WRITER]{SHOW_WRITER_LINK}[ELSEIF USER_STATUS_TESTER]{SHOW_TESTER_LINK}[ELSE]{SHOW_ALL_LINK}[/IF]';

$pos = strpos($str, '[IF ');
A new problem arose... Finding the first "[IF " was going fine, but finding the USER_STATUS_ADMIN between "[IF " and "]" was giving me trouble...

So here I am now, which method I should focus my energy on and how to achieve my goal.

Any help on the matter would be greatly appreciated,

Thanks !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-07-2011, 06:08 AM
pottiq pottiq is offline
Junior Member
 
Join Date: Dec 2011
Posts: 2
pottiq is on a distinguished road
No one can help me? This problem has troubled me for a long time!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-16-2011, 09:34 PM
hatnohat hatnohat is offline
Junior Member
 
Join Date: Dec 2011
Posts: 4
hatnohat is on a distinguished road
What CMS is this for? I've not used IF statments enclosed in [] brackes before.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:38 AM.


Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.0.0
© 2004-2011 AffiliateSeeking. All rights reserved.