/    Sign up×
Community /Pin to ProfileBookmark

Synthax when calling variable from external php file

Here is an example of a problem i have:
I have index.php which calls a function which needs a variable from en.php.
en.php contains text strings for the site. In index.php we have a function that when the amount of content is limited per page, produces links to the previous and next pages. The text for these links will change languages, and i need to call the proper text from the language file, in this example, en.php. But my synthax is wrong, can somebody tell what’s off?

This is en.php

[CODE]<?php
// Declare all text strings that we need,
// in English.
$GLOBALS[‘text’] = array (
‘prevpage’ => ‘Previous page’,
‘nextpage’ => ‘Next page’,
);
?>[/CODE]

This is index.php

[CODE]<?php
require_once ‘language/en.php’;

function getPagingLink($totalResults, $pageNumber, $itemPerPage = 3, $strGet = ”)
{

… …

if ($totalPages > 1) {
$self = ‘http://’ . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘PHP_SELF’] ;

// print ‘previous’ link only if we’re not
// on page one
if ($pageNumber > 1) {
$page = $pageNumber – 1;
if ($page > 1) {
$prev = ” <a href=”$self?pageNum=$page”>$text[‘prevpage’]</a> “;

… …
[/CODE]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@DJRobThaManJul 23.2008 — why not just encapsulate the declaration of the variables in en.php inside a function and add a return statement. Then after including en.php in the index you can run the function which will allow you to load those values into a local variable like this:

en.php
[code=php]
function getvars()
{
return array ('prevpage' => 'Previous page','nextpage' => 'Next page'),...);
}
[/code]


index.php
[code=php]
include("en.php");
$text = getvars();
[/code]
×

Success!

Help @igotosleepat2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...