[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 02-16-2007, 10:24 AM   #1 (permalink)
NamePros Regular
 
beaver6813's Avatar
 
Join Date: May 2005
Location: England
Posts: 349
65.50 NP$ (Donate)

beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough


Prevent Arrays From Executing Value....

Hey,

Okay i am writing a bulk replacer that searches a document for a certain tag and then replaces it with the appropriate value/function value.

But.. is there a way to get it not to execute every damn function listed in the array... god its hard to explain, ill let the code do the talking:
PHP Code:
$page='
<-(GET_HEADER)->
Thats the header.. then i think ill have a footer
<-(GET_FOOTER)->'
;

$MasterArray=array('<-(GET_HEADER)->','<-(GET_FOOTER)->','<-(GET_SIDEBAR_LEFT)->');

$MasterFinalArray=array(get_header(),get_footer(),get_side_left());

$replace=str_replace($MasterArray,$MasterFinalArray,$page);
Unfortunately it seems to.. when looping through the arrays execute any functions it finds each time, meaning i end up with obsurd numbers of database queries for simple pages when some tags are not in use.. in this example get_side_left() will be executed even though there is no tag for it...

Any ideas how to get it to to only execute tags found in the script? (Note that functions like get_header() will get the header file and bring some extra tags into the equation :P So thats why i've had to do it using this method in order...

How do i get it to stop executing functions that aren't needed!
__________________
-Beaver6813.com V5 Soon!
beaver6813 is offline  
Old 02-16-2007, 10:31 AM   #2 (permalink)
Adrian
 
Hitch's Avatar
 
Join Date: Aug 2005
Location: Uk, South Yorkshire
Posts: 1,227
16.00 NP$ (Donate)

Hitch is a splendid one to beholdHitch is a splendid one to beholdHitch is a splendid one to beholdHitch is a splendid one to beholdHitch is a splendid one to beholdHitch is a splendid one to beholdHitch is a splendid one to behold

Animal Rescue Third World Education Find Marrow Donors!
Not entirely sure, and i don't really have time to look into it, now.

However, it looks like somesort of template system, am i right?
If so, you could take a look at my class, http://www.dreamit.co.uk/php-template-system-class/

That would work fine, and you can easily specify what to replace in what file.

Adrian
__________________
NamePros
Hitch is online now  
Old 02-16-2007, 11:29 AM   #3 (permalink)
NamePros Regular
 
beaver6813's Avatar
 
Join Date: May 2005
Location: England
Posts: 349
65.50 NP$ (Donate)

beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough


Thanks Looks sweet ^^

Although because there are tags in more than one file... and then tags also in those files it makes it hard to replace them like you have but it certainly is some very clean code

Resolved! Thanks Hitch I had a look at your code and then compared to mine, realized that it wasn't executing the functions and instead the db query counter was up the creek... fixed now :P

Thanks & $Rep++;
__________________
-Beaver6813.com V5 Soon!
beaver6813 is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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

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


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 07:40 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85