Jump to content

[SOLVED] function help?


cmzone

Recommended Posts

I am including a functions.php file in my index.html with one function that uses a multidimensional array data that is included as well, but I am getting an error that halts the loading of the page.

 

Here is the error:

Parse error: syntax error, unexpected T_FUNCTION in /home1/stomperg/public_html/nintendogamesonline/functions.php on line 3

 

And here is the code to create the function that I am including:

 

<? php

 

function showMonitor($monitor)

{

echo(

<div class="section">

<div class="images">

<img class="logo" src="images/logos/hannsg.png" alt="Hanns-G" />

<img class="monitor" src="images/hannsg/$monitor.jpg" alt="Hanns-G $monitor" />

</div>

<div class="description">

<a href="#"></a>

<ul>

<li><strong>Color:</strong> $hannsg['$monitor'][0]</li>

<li><strong>Size:</strong> $hannsg['$monitor'][1]</li>

<li><strong>Resolution:</strong> $hannsg['$monitor'][2]</li>

<li><strong>Response Time:</strong> $hannsg['$monitor'][3]</li>

<li><strong>Input:</strong> $hannsg['$monitor'][4]</li>

<li><strong>Brightness:</strong> $hannsg['$monitor'][5]</li>

<li><strong>Contrast Ratio:</strong> $hannsg['$monitor'][6]</li>

<li><strong>Viewing Angle:</strong> $hannsg['$monitor'][7]</li>

<li><strong>Pixel Pitch:</strong> $hannsg['$monitor'][8]</li>

</ul>

</div>

<div class="revieworbuy">

</div>

<div class="clear"></div>

</div>);

}

 

?>

 

 

 

Can anyone tell me what is wrong? Thanks!

 

 

Link to comment
Share on other sites

<?php

function showMonitor($monitor)
{
<<<HRD
           <div class="section">
              <div class="images">
                 <img class="logo" src="images/logos/hannsg.png" alt="Hanns-G" />
                 <img class="monitor" src="images/hannsg/$monitor.jpg" alt="Hanns-G $monitor" />
              </div>
              <div class="description">
                 <a href="#">[/url]
                 <ul>
                    <li><strong>Color:</strong> $hannsg['$monitor'][0]</li>
                    <li><strong>Size:</strong> $hannsg['$monitor'][1]</li>
                    <li><strong>Resolution:</strong> $hannsg['$monitor'][2]</li>
                    <li><strong>Response Time:</strong> $hannsg['$monitor'][3]</li>
                    <li><strong>Input:</strong> $hannsg['$monitor'][4]</li>
                    <li><strong>Brightness:</strong> $hannsg['$monitor'][5]</li>
                    <li><strong>Contrast Ratio:</strong> $hannsg['$monitor'][6]</li>
                    <li><strong>Viewing Angle:</strong> $hannsg['$monitor'][7]</li>
                    <li><strong>Pixel Pitch:</strong> $hannsg['$monitor'][8]</li>
                 </ul>
              </div>
              <div class="revieworbuy">
              </div>
              <div class="clear"></div>
           </div>
HRD;
}

?>

 

Use the heredoc syntax to echo raw html.. be sure that the closing HRD; is NOT indented, it must be the first thing on a line by itself.

 

You don't need to use the letters HRD either, it's up to you.  But that code above should work.

Link to comment
Share on other sites

wow you guys are fast. but I have a new error. definately something to do with the multidimensional array...

 

Error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home1/stomperg/public_html/nintendogamesonline/functions.php on line 13

 

Code:

<?php

function showMonitor($monitor)

{

<<<HRD

            <div class="section">

              <div class="images">

                  <img class="logo" src="images/logos/hannsg.png" alt="Hanns-G" />

                  <img class="monitor" src="images/hannsg/$monitor.jpg" alt="Hanns-G $monitor" />

              </div>

              <div class="description">

                  <a href="#">[/url]

                  <ul>

                    <li><strong>Color:</strong> $hannsg['$monitor'][0] </li>

                    <li><strong>Size:</strong> $hannsg['$monitor'][1] </li>

                    <li><strong>Resolution:</strong> $hannsg['$monitor'][2] </li>

                    <li><strong>Response Time:</strong> $hannsg['$monitor'][3] </li>

                    <li><strong>Input:</strong> $hannsg['$monitor'][4] </li>

                    <li><strong>Brightness:</strong> $hannsg['$monitor'][5] </li>

                    <li><strong>Contrast Ratio:</strong> $hannsg['$monitor'][6] </li>

                    <li><strong>Viewing Angle:</strong> $hannsg['$monitor'][7] </li>

                    <li><strong>Pixel Pitch:</strong> $hannsg['$monitor'][8] </li>

                  </ul>

              </div>

              <div class="revieworbuy">

              </div>

              <div class="clear"></div>

            </div>

HRD;

}

?>

Link to comment
Share on other sites

<?php
function showMonitor($monitor)
{
<<<HRD
            <div class="section">
               <div class="images">
                  <img class="logo" src="images/logos/hannsg.png" alt="Hanns-G" />
                  <img class="monitor" src="images/hannsg/$monitor.jpg" alt="Hanns-G $monitor" />
               </div>
               <div class="description">
                  <a href="#"></a>
                  <ul>
                     <li><strong>Color:</strong> {$hannsg['$monitor'][0]} </li>
                     <li><strong>Size:</strong> {$hannsg['$monitor'][1]} </li>
                     <li><strong>Resolution:</strong> {$hannsg['$monitor'][2]} </li>
                     <li><strong>Response Time:</strong> {$hannsg['$monitor'][3]} </li>
                     <li><strong>Input:</strong> {$hannsg['$monitor'][4]} </li>
                     <li><strong>Brightness:</strong> {$hannsg['$monitor'][5]} </li>
                     <li><strong>Contrast Ratio:</strong> {$hannsg['$monitor'][6]} </li>
                     <li><strong>Viewing Angle:</strong> {$hannsg['$monitor'][7]} </li>
                     <li><strong>Pixel Pitch:</strong> {$hannsg['$monitor'][8]} </li>
                  </ul>
               </div>
               <div class="revieworbuy">
               </div>
               <div class="clear"></div>
            </div>
HRD;
}
?>

Link to comment
Share on other sites

ok great now no errors but not doing what I want and it was working manually by putting the code in before.

 

Whatever I put in the variable $monitor should replace whatever I put in the code, correct? I am calling the function as so:

<?php showMonitor("JW-199DPB"); ?>

 

The multidimensional array callings should still work with those '{}' around it, right?

 

Almost there... thanks guys!

Link to comment
Share on other sites

okay then my problem is that the div isnt submitting at all, like the function isnt appearing, as if the <<<HRD is hiding everything because not even the div is showing up after calling the function

 

 

what i what to happen is when the function is called, i want the parameter to replace all the variables in the code and then i want the function to print the raw code onto the html document exactly where it is called.  maybe this helps some more?

 

thanks for all your help dezkit and all

Link to comment
Share on other sites

no more errors but the function is not working at all.

 

what i what to happen is when the function is called, i want the parameter to replace all the variables i specified in the function itself, and then i want the function to print the raw code onto the html document exactly where it is called.  maybe this helps some more?

Link to comment
Share on other sites

<?php
function showMonitor($monitor)
{
echo <<<HRD
            <div class="section">
               <div class="images">
                  <img class="logo" src="images/logos/hannsg.png" alt="Hanns-G" />
                  <img class="monitor" src="images/hannsg/$monitor.jpg" alt="Hanns-G $monitor" />
               </div>
               <div class="description">
                  <a href="#"></a>
                  <ul>
                     <li><strong>Color:</strong> {$hannsg[$monitor][0]} </li>
                     <li><strong>Size:</strong> {$hannsg[$monitor][1]} </li>
                     <li><strong>Resolution:</strong> {$hannsg[$monitor][2]} </li>
                     <li><strong>Response Time:</strong> {$hannsg[$monitor][3]} </li>
                     <li><strong>Input:</strong> {$hannsg[$monitor][4]} </li>
                     <li><strong>Brightness:</strong> {$hannsg[$monitor][5]} </li>
                     <li><strong>Contrast Ratio:</strong> {$hannsg[$monitor][6]} </li>
                     <li><strong>Viewing Angle:</strong> {$hannsg[$monitor][7]} </li>
                     <li><strong>Pixel Pitch:</strong> {$hannsg[$monitor][8]} </li>
                  </ul>
               </div>
               <div class="revieworbuy">
               </div>
               <div class="clear"></div>
            </div>
HRD;
}
?>

 

Sorry I forgot to echo the string.. also thrope is right you need to pass that hannsg array to the function or define it within the function...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.