Working with 2 multidimensional arrays in a loop
Posted: Fri Dec 24, 2010 2:23 pm
Ok, I'm fairly new to PHP, but I've been able to figure most everything out so far. I ran into a problem that I could really use some help with.
First of all, I'm dealing with a proprietary cms, that my boss payed $10,000 for.
This CMS uses Tinymce, to edit html code which it stores in our database. Then the content is simply retrieved, and echoed to the main content division.
2 Problems with this: I can not have dynamic database content, directly in any of my pages, and I end up with a new php template for every new thing I want to do, like displaying a database search. So when I want to make a change to any sidebar or anything, I have to make that change in *15 different php templates.
So here is what I'm trying to do: I added support for a custom html tag in Tiny_MCE, let's say my tag is just <bens>. So, I write my php code between the <bens> tag, tinymce doesn't strip it out, and it gets stored in the database. Now the tricky part:
In the main php template, the page content is retrieved and is stored to the $content variable. After this happens, I run a preg_match_all for code between the <ben> tags. I capture the code, and the offset, and at creates a multidimensional array with the php code, and where it was in the $content. Then I run a preg_split on the <bens> tag, and all code between it, and capture the output, which gives me chunks of normal code that was around the <bens> tag. So after this I end up with 2 multidimensional arrays.
How I want these to work is: If there is a <bens> tag first, evaluate it, and then display the normal content, UP to the next <bens> tag. Then evaluate that, display the next chunk of normal content, and so on, until it reaches the end. This should give me dynamic access to php, from within my pages, and eliminate the need for 15 different php templates.
How I would like to be able to do it in a perfect world, is to load up both arrays in a single for each loop. then have variables passed from both arrays like: $htmlkey $htmlvalue, and $phpkey $phpvalue. Then I could just do echo $htmlvalue , eval $phpvalue.
I can not figure out how to set up a foreach loop to iterate through 2 different multidimensional arrays at the same time, passing their variables to the loop. The fact that they are multidimensional makes it more difficult.
Am I going about this completely wrong? Do I need to combine the arrays somehow? Does anybody have any suggestions? I would appreciate any help at all, Thank you very much.
First of all, I'm dealing with a proprietary cms, that my boss payed $10,000 for.
This CMS uses Tinymce, to edit html code which it stores in our database. Then the content is simply retrieved, and echoed to the main content division.
2 Problems with this: I can not have dynamic database content, directly in any of my pages, and I end up with a new php template for every new thing I want to do, like displaying a database search. So when I want to make a change to any sidebar or anything, I have to make that change in *15 different php templates.
So here is what I'm trying to do: I added support for a custom html tag in Tiny_MCE, let's say my tag is just <bens>. So, I write my php code between the <bens> tag, tinymce doesn't strip it out, and it gets stored in the database. Now the tricky part:
In the main php template, the page content is retrieved and is stored to the $content variable. After this happens, I run a preg_match_all for code between the <ben> tags. I capture the code, and the offset, and at creates a multidimensional array with the php code, and where it was in the $content. Then I run a preg_split on the <bens> tag, and all code between it, and capture the output, which gives me chunks of normal code that was around the <bens> tag. So after this I end up with 2 multidimensional arrays.
How I want these to work is: If there is a <bens> tag first, evaluate it, and then display the normal content, UP to the next <bens> tag. Then evaluate that, display the next chunk of normal content, and so on, until it reaches the end. This should give me dynamic access to php, from within my pages, and eliminate the need for 15 different php templates.
How I would like to be able to do it in a perfect world, is to load up both arrays in a single for each loop. then have variables passed from both arrays like: $htmlkey $htmlvalue, and $phpkey $phpvalue. Then I could just do echo $htmlvalue , eval $phpvalue.
I can not figure out how to set up a foreach loop to iterate through 2 different multidimensional arrays at the same time, passing their variables to the loop. The fact that they are multidimensional makes it more difficult.
Am I going about this completely wrong? Do I need to combine the arrays somehow? Does anybody have any suggestions? I would appreciate any help at all, Thank you very much.