View Full Version : Another Newbie Needs Help.
Temper
09-17-2002, 09:42 PM
I want to make a script that imputs <BR> tags when I load a page. For example, in a text file, along with my source code for the html, I'd have somthing like
<?
$BR = 5;
?>
Then when my main page loads that text file, I'd want it to give the $BR value (5) to the script that would imput the "Echo "<BR>;" on the page 5 times (or whatever value I assign to the $BR ). What I came up with was:
<?
$BR = A$;
$B = Echo "<BR>";
If
A$ > 0;
$A *= B$;
?>
Now, obviously that didn't work, because I'm here asking for help, but for you advanced people who notice that I really have no clue what I'm doing, you may be able to look at that to see what I'm "trying" to do, and maybe tell me the correct way to do it, because I'm an idiot who can't do it by himself.
If you can help me, that'll be great.
~Temper
Dylan Leblanc
09-17-2002, 11:06 PM
<?
$br = 5;
for ($i = 0; $i < $br; $i++)
echo'<BR>';
?>
Temper
09-18-2002, 08:48 PM
Is there any way that I can make it somthing like
"$br = $a; ", where "$a" gets it's value from a link or somthing like that? Say I have an HTML link, like:
<a href="index.php?main=files/main.php" Name=$A= 20> Text </A>
If you understand what I mean there, you put the $a variable in the link so when the text file loads in, the index.php template inserts "<br>" tags into the index.php source.
As I said before, I have no clue how to do this in a correct manner, so could you please enlighten me as to how to go about doing this kind of script correctly?
Thanks
~Temper
mordred
09-18-2002, 11:54 PM
Trying to answer your first question, on how to get the value of GET parameters:
The only thing you have to do is to assign them to your variable by referencing it in the $_GET array. But check your php version first, there was a paradigm shift in php 4.1.
php version < 4.1:
if (isset($HTTP_GET_VARS['a'])) {
$br = $HTTP_GET_VARS['a'];
}
php version >= 4.1:
if (isset($_GET['a'])) {
$br = $_GET['a'];
}
Note that in the later versions, the $HTTP_x arrays are still available, but only for backwards compatibility, and they aren't superglobal, which means that if you're trying to use them inside of functions you either have to pass them as parameters or import them with the global keyword.
Ok, I hope that illustrates my point clearly enough and does not add to your confusion.
About your second question, it depends on how you include the file contents. Are you using include/require or do you open it with a filesystem related function? If the former is the case, you simply have to define the variable in your including file and then the variable will be available in the included file. Because PHP drops out of php mode when including files, all you have to do is to write <?php echo $br; ?> anywhere where you want it into the source of the included files.
On the other hand, you could open the file via an URL in fopen() similarly to what I said above.
But if you are retrieving the file as a string variable, you will have to get aquainted to string functions and especially regexp functions for replacing the template variables. Or use one of the template libraries as Smarty, FastTemplate, IT[X] etc...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.