| Author |
Message |
Antra
Sergeant


Joined: Mar 15, 2003
Posts: 143
|
Posted:
Wed Apr 30, 2003 3:56 pm |
  |
I have a function defined that upon calling it, this function(); works just fine. But I'd like the text to be displayed just below the header graphic. I don't know how to take this PHP function call and make the output appear where I want it to. This is one of the final tweaks I'm going to be doing to my site and I'd like to take a break from nuking for a while . Any tips? |
|
|
    |
 |
Raven
General


Joined: Mar 22, 2003
Posts: 5233
Location: USA
|
Posted:
Wed Apr 30, 2003 5:08 pm |
  |
I assume when you say 'this text' you are referring to the output of your function? In any event, modify the theme. Find where your logo.gif is called (ex. header.html if using fiapple) and call the function from there. |
_________________ Those who hear not the music think the dancers mad.
Raven Web Hosting|My Scripts & Stuff |
|
    |
 |
Antra
Sergeant


Joined: Mar 15, 2003
Posts: 143
|
Posted:
Thu May 01, 2003 8:03 am |
  |
That's just it. How do you call a PHP function from within HTML? And yes, it's header.html -- using a heavily modified smartDark. |
|
|
    |
 |
Raven
General


Joined: Mar 22, 2003
Posts: 5233
Location: USA
|
Posted:
Thu May 01, 2003 8:14 am |
  |
You use embedded php code. Here is a snippet of the header.html code from the NukeNews theme.
| Code: |
<br>
<table cellpadding="0" cellspacing="0" width="100%" border="0" align="center" bgcolor="#ffffff">
<tr>
<td bgcolor="#ffffff">
<img height="16" alt="" hspace="0" src="themes/NukeNews/images/corner-top-left.gif" width="17" align="left">
<a href="index.php"><img src="themes/NukeNews/images/logo.gif" align="left" alt=""._WELCOMETO." $sitename" border="0" hspace="10"></a></td> |
To embed php code, you would do something like this.
| Code: |
<br>
<table cellpadding="0" cellspacing="0" width="100%" border="0" align="center" bgcolor="#ffffff">
<tr>
<td bgcolor="#ffffff">
<img height="16" alt="" hspace="0" src="themes/NukeNews/images/corner-top-left.gif" width="17" align="left">
<a href="index.php"><img src="themes/NukeNews/images/logo.gif" align="left" alt=""._WELCOMETO." $sitename" border="0" hspace="10"></a><br><?=textFunction();?></td> |
There are many different ways and it will depend on your function of course. |
_________________ Those who hear not the music think the dancers mad.
Raven Web Hosting|My Scripts & Stuff |
|
    |
 |
Antra
Sergeant


Joined: Mar 15, 2003
Posts: 143
|
Posted:
Thu May 01, 2003 8:21 am |
  |
*facepalm* I knew it was something easy like that. I'm a php hack, not a programmer . Thanks! |
|
|
    |
 |
Antra
Sergeant


Joined: Mar 15, 2003
Posts: 143
|
Posted:
Thu May 01, 2003 8:29 am |
  |
Actually, I can't get that to go. Here's what I'm putting in, with the function titled "randomquote" and requiring no input:
| Code: |
| <?=randomquote();?> |
I've got the right spot in html, but nothing appears at all...what php file does this function need to be defined in? For now I have it in mainfile.php to be sure it'll be found. |
|
|
    |
 |
Raven
General


Joined: Mar 22, 2003
Posts: 5233
Location: USA
|
Posted:
Thu May 01, 2003 8:32 am |
  |
Does randomquote() return a text string?
You could just place the randomquote function at the beginning of your header.html file instead of mainfile. |
_________________ Those who hear not the music think the dancers mad.
Raven Web Hosting|My Scripts & Stuff |
|
    |
 |
Antra
Sergeant


Joined: Mar 15, 2003
Posts: 143
|
Posted:
Thu May 01, 2003 8:39 am |
  |
Aye, it does. I feel stupid for not looking around the 'net more, but from the tutorials I saw (now that you gave me the word "embedded" to search on) it looks like it should be <?php stuff;?> ? Not complaining, I'll go your way .
Just playing around I added this to theme.php under function themeheader: $randomquote = randomquote();
At the very top of the page, outside of all tables and looking just the way I want it to (but not where), it displays the text.
Edit: I tried putting the function definition in the header.html, but I think theme.php (when it calls that file) chokes on it since I kept getting repeated errors. I'm keeping it in mainfile for now. |
|
|
    |
 |
Raven
General


Joined: Mar 22, 2003
Posts: 5233
Location: USA
|
Posted:
Thu May 01, 2003 8:54 am |
  |
Is for use when you have to do more than just display code. The code I gave you
| Code: |
| <?=randomquote();?> |
assumes that randomquote returns a text string that you would then display with an echo statement. It's a shorthand way is all. You just as easily could place both your function code and the echo statement all within the <? ?> at the spot where you want it displayed. If it isn't working, check your apache error_log to see if there is an error being thrown. |
_________________ Those who hear not the music think the dancers mad.
Raven Web Hosting|My Scripts & Stuff |
|
    |
 |
Antra
Sergeant


Joined: Mar 15, 2003
Posts: 143
|
Posted:
Thu May 01, 2003 10:15 am |
  |
If I place it in theme.php it works (kinda) as described above. If I put it in the code example you've shown me here, it returns nothing. Starting to weird me out... |
|
|
    |
 |
Raven
General


Joined: Mar 22, 2003
Posts: 5233
Location: USA
|
Posted:
Thu May 01, 2003 10:33 am |
  |
If you want it looked at any further, you are going to need to post the code down to the point that you embed it. |
_________________ Those who hear not the music think the dancers mad.
Raven Web Hosting|My Scripts & Stuff |
|
    |
 |
Antra
Sergeant


Joined: Mar 15, 2003
Posts: 143
|
Posted:
Thu May 01, 2003 10:42 am |
  |
Code in mainfile.php:
| Code: |
function randomquote() {
$RANDOM_QUOTE_FILE = "quotes.txt";
srand((double)microtime()*1000000);
if (file_exists($RANDOM_QUOTE_FILE)) {
$array_txt = preg_split("/--NEXT--/", join('', file($RANDOM_QUOTE_FILE)));
echo "<center><i>".$array_txt[rand(0, sizeof($array_txt) -1)]."</i></center>";
} else {
echo "Error: can't open $RANDOM_QUOTE_FILE file";
}
}
|
Code in header.html:
| Code: |
| <?=randomquote();?> |
|
|
|
    |
 |
Raven
General


Joined: Mar 22, 2003
Posts: 5233
Location: USA
|
Posted:
Thu May 01, 2003 10:44 am |
  |
Your function is NOT returning a text string. That's the problem. Your function ECHOS a text string. Try this:
<? randomquote(); ?>
If this still is not workling, I would imagine it's a pathing error to quotes.txt. Check your apache error_log, or insert a debug statement right at the top like
| Code: |
| echo 'Result = '.file_exists("quotes.txt");die(); |
If it does not return a 1, then it cannot locate the file. |
_________________ Those who hear not the music think the dancers mad.
Raven Web Hosting|My Scripts & Stuff |
|
    |
 |
Antra
Sergeant


Joined: Mar 15, 2003
Posts: 143
|
Posted:
Thu May 01, 2003 12:13 pm |
  |
Oh...sorry, didn't realize the difference. Would it be advisable to tweak it to return rather than echo? The debug string you gave me did indeed return a 1 with my quotes.txt in the phpnuke root.
So, the file is visible. My function is in mainfile.php. I'm calling it with <? randomquote();?>, and nothing shows up. However, I do see the function call directly within the html delievered to the browser. So it's not being evaluated/parsed...could this be a server setting?
Edit/addendum: I also tried doing a silly string like <?php echo "<p>Hello World</p>"; ?>, and it ALSO didn't parse. To me it's looking like any PHP put into the html pages, which will be called by php pages, isn't parsing. |
|
|
    |
 |
|
|