searching contents of current file

Is there a way to search only the current document for code in that file?

I design templates for a system that can insert side columns on certain pages. This is done through php includes.

I want to write some php that will search the current page for the div id names that will be inserted through those includes.

That will let me know if those columns have been used on that page.

Is this possible?

thanks,
Mike

hello Mike, can you post some code so i can provide you answer or suggest you something.

if you want check this thing once html is render that this possible using Ajax.

so explain your issue in detail with some part of code.

~~SR~

Mike, yes it can be done. EVERYTHING can be done. But, first, what do you mean by “current page”???
You said you want to write some PHP code to search the “current page”…

If you mean you are executing a PHP page that has placed some HTML onto the new page your are posting, you can “capture” that page easily using PHP Object functions. You would basically start the PHP Object before you put out anything and just before you search the page, you would close the PHP Object and do your search.
The only problem is that you could do this much easier just keeping flags while building your page.

If you mean you want to pull the “LIVE” page that posts to a PHP page, that is very hard to do. It can be done, but, not the way you are thinking. You would have to keep an image of the page before it is posted to the browser. Then, when the browser posts to the PHP page, it would use this cached page for your scanning. But, again, you could just do this with flags…

Simple flags could be a few SESSION variables such as $_SESSION[‘previousdiv1’]=“true”; $_SESSION[‘previousdiv20’]=“false”; Where this would indicate if the previous page’s div#1 is used and div#20 is not. Something like that… No scanning pages, just pass on some variables…

Perhaps you should clarify what you really want to do… Help us help you…

Thank you guys for your replies. I thought I was being pretty clear, but obviously my grasp of php must be worse than I thought : )

I will check out the Session idea.

Here is the code I am trying to make work, with my explanation:

<?php if (('
') AND ('
')) { echo '
'; } elseif ('
' or '
') { echo '
'; } else { echo '
'; } ?>

Unfortunately I don’t know how the system that generates the pages works, but some pages on a website can call for the custom-left area, or the custom-right area. This is for a template but not all the pages on the actual website will display the same. Very similar to how Joomla works, you can have the sidebars show on some pages. Except, this system doesn’t work anything like Joomla. So you might have only the first page showing the right sidebar column area, and all the other pages not showing any sidebar column areas, but all pages would use the same template.

So the above code would (if it worked) search the page to see if div id=“custom-left” is in the code. If so, then we know that the left column is showing on that page and we need to adjust the center column width. (the div id=“custom-left” is written in side the php include file itself)

The idea is, if the current page shows both div ids for custom-left and custom-right then the center column would be the most narrow width (content-both is the css call for the most narrow center column width).

If it shows only one div id for either custom-left or custom-right then it would call for the medium width center column, content-site. And if neither then content-full which is the full width allowed with no sidebars showing.

So, to further complicate matters, the custom-left and custom-right sidebar areas are called by php includes.

Also, the order of the page when displayed with both side bars:
custom-left
content
custom-right

Ideally I would put the above code just above the actual content area as that is where the div id defining the content width would normally go. But if the above code actually worked then it would never see the custom-right because the code searching the page would execute before the custom-right php include would put it on the page. But I am trying to only cross one bridge at a time. If I could get the above code to work I think I could work out the rest.

Any help you could offer would be greatly appreciated.

Thanks,
Mike

If yer page output is done afterwards, you can just use variables to modify the output, simple but requires a lot of planning/thought
if yer page output is done beforehand, u will want to use a buffering system, so output is suspended until processing is done, processing as in adjusting yer divs.

I reread your posts and I think we are still unsure what you are actually trying to do.
As far as I see it, you have PHP code that “includes” a file into the current file in some code.
Of course, you did not show us how that code works. I will assume you have a variable that
contains the file needed to be loaded by an include command. So, you want to load that file
conditionally? Correct? Well, you can do this with session variables with ease. Or, you could
do the complicated version you mentioned by scanning the current file. Either is possible.

First, let’s explain how PHP works. First, you request a PHP page on the server. The page is executed
SERVER-SIDE and the PHP code is executed. The results of the HTML page along with anything outputted
from the PHP code is then sent to the browser. The browser then “renders” the display using HTML, CSS,
Javascript (CLIENT-SIDE) and other in-browser programming tools. So, when all of this happens, the
PHP code is SERVER-SIDE only. Therefore, there really isn’t a “current page” running at any one monent
in time. The “LIVE” current page depends on where you are talking about. If you are talking about the
current page in the PHP code, it is the actual page SERVER-SIDE before it is displayed on the screen.

If you are talking about that “LIVE” page, you can load the page into a variable with very little code.
Then, you can just use a string search to locate if those tags such as “

” are inside
the string. Then, your if then code would sort it out for you. But, the problem with this is where do these
tags come from to start with? If you are programming a variable display where these tags are loaded,
why are you not just doing your new code in that code instead of trying to do it in a new page?

Did that make sense? If you are attempting to “ADD” content to a page already designed and posted to
the screen, you would have to do that CLIENT-SIDE which would mean using Javascript to load the new
content. If you want to do it SERVER-SIDE in PHP, just do it in the same code that creates the tags in
the first place. Hope that makes sense… Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service