Re: how to insert html code with PHP
[email protected] (Jim Giner)
| Newsgroups | php.general |
|---|---|
| Message-ID | <[email protected]> |
On 4/11/2013 10:48 AM, Rafnews wrote:
> On 11.04.2013 13:34, Rafnews wrote:
>> Hi,
>>
>> I would like to insert a piece of HTML code inside several pages.
>> all pages are differently named.
>>
>> i need in each page to find a particular tag, let's say <div
>> id="#submenu">...</div> (so based on its ID and tagname) and inside it
>> to insert my PHP/HTML code.
>>
>> how can i do that ?
>>
>> thx.
>>
>> A.
>
> Ok i can write an include_once('myfile.php');
>
> however if i have an array in this file, other files where is the
> include_once(); do not recognize the array.
>
> here is an extract of this file to include (submenu.php):
> <?php
> $submenu = array();
> $submenu[] = array('id' => 1,'class'=>'menuitem1');
> $submenu[] = array('id' => 2,'class'=>'menuitem2');
>
> // function in the same file
> function DisplayMenu($title){
> // here i do not have access to the previous array $submenu define
> outside the function
> ...
> }
>
> as it is included the function DisplayMenu should also have access to
> $submenu array, no ?
>
>
>
basic php question. Variables within any function are local to that
function (except for superglobals like $_POST, $_SESSION, etc.). In
order to reference a var defined/used outside that function you must add
a global statement in the function:
function xxxx()
{
global $submenu;
...
...
}