cmzone Posted August 10, 2008 Share Posted August 10, 2008 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 https://forums.phpfreaks.com/topic/118986-solved-function-help/ Share on other sites More sharing options...
trq Posted August 10, 2008 Share Posted August 10, 2008 Id start by changing... <? php to.... <?php Link to comment https://forums.phpfreaks.com/topic/118986-solved-function-help/#findComment-612696 Share on other sites More sharing options...
trq Posted August 10, 2008 Share Posted August 10, 2008 Oh, and strings need be within quotes so your entire echo() needs fixing. Link to comment https://forums.phpfreaks.com/topic/118986-solved-function-help/#findComment-612698 Share on other sites More sharing options...
rawb Posted August 10, 2008 Share Posted August 10, 2008 <?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 https://forums.phpfreaks.com/topic/118986-solved-function-help/#findComment-612699 Share on other sites More sharing options...
cmzone Posted August 10, 2008 Author Share Posted August 10, 2008 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 https://forums.phpfreaks.com/topic/118986-solved-function-help/#findComment-612702 Share on other sites More sharing options...
dezkit Posted August 10, 2008 Share Posted August 10, 2008 <?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 https://forums.phpfreaks.com/topic/118986-solved-function-help/#findComment-612705 Share on other sites More sharing options...
cmzone Posted August 10, 2008 Author Share Posted August 10, 2008 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 https://forums.phpfreaks.com/topic/118986-solved-function-help/#findComment-612708 Share on other sites More sharing options...
dezkit Posted August 10, 2008 Share Posted August 10, 2008 yes Link to comment https://forums.phpfreaks.com/topic/118986-solved-function-help/#findComment-612710 Share on other sites More sharing options...
cmzone Posted August 10, 2008 Author Share Posted August 10, 2008 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 https://forums.phpfreaks.com/topic/118986-solved-function-help/#findComment-612711 Share on other sites More sharing options...
cooldude832 Posted August 10, 2008 Share Posted August 10, 2008 Oh, and strings need be within quotes so your entire echo() needs fixing. echo() is valid to use as a function but yes you must quote any strings in there as strings Link to comment https://forums.phpfreaks.com/topic/118986-solved-function-help/#findComment-612713 Share on other sites More sharing options...
cmzone Posted August 10, 2008 Author Share Posted August 10, 2008 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 https://forums.phpfreaks.com/topic/118986-solved-function-help/#findComment-612714 Share on other sites More sharing options...
trq Posted August 10, 2008 Share Posted August 10, 2008 The $hannsg array does not exist within your function. Even if it did you would need use... $hannsg[$monitor][0] and not.... $hannsg['$monitor'][0] Link to comment https://forums.phpfreaks.com/topic/118986-solved-function-help/#findComment-612795 Share on other sites More sharing options...
rawb Posted August 10, 2008 Share Posted August 10, 2008 <?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 https://forums.phpfreaks.com/topic/118986-solved-function-help/#findComment-612808 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.