No, there are no JS errors.
Here is what my code looks like (by the way my variable is called $menuhtml):

function menuhtml() {
return '
|
<a href="'.$menu0URL.'">'.$menu0LINK.'</a> |
<a href="'.$menu1URL.'">'.$menu1LINK.'</a> |
<a href="'.$menu2URL.'">'.$menu2LINK.'</a> |
<a href="'.$menu3URL.'">'.$menu3LINK.'</a> |
<a href="'.$menu4URL.'">'.$menu4LINK.'</a> |
<a href="'.$menu5URL.'">'.$menu5LINK.'</a> |
<a href="'.$menu6URL.'">'.$menu6LINK.'</a> |
';
}
$menuhtml = menuhtml();
$menuhtml = str_replace('|','<br>',$menuhtml);
echo '
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
if (!useRedirect) { // if dynamic embedding is turned on
if(hasRightVersion) { // if we detected an acceptable version
var oeTags = \'<object classid="clsid😃27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="339" height="284">\'
+ \' <param name="movie" value="menu.swf?phpself='.$SERVER["PHP_SELF"].'&b='.$b.'">\'
+ \' <param name="quality" value="high">\'
+ \' <embed src="menu.swf?phpself='.$
SERVER["PHP_SELF"].'&b='.$b.'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="339" height="284"><\/embed>\'
+ \'<\/object>\';
document.write(oeTags); // embed the flash movie
} else { // flash is too old or we cannot detect the plugin
// NOTE: height, width are required!
var alternateContent = \'<table width="339" height="284" border="0" cellpadding="0" cellspacing="0"><tr><td><font size="2"><b><div align="right">'.$menuhtml.'</div></font></b></td></tr></table>\';
document.write(alternateContent); // insert non-flash content
}
}
// -->
</SCRIPT>
';

I shall point out that interestingly enough the variables $b and $_SERVER["PHP_SELF"] do come through without a problem but the var $menuhtml doesn't...

also I should point out that if I do an echo $menuhtml; I get a menu, but if I want to print the contents of $menuhtml inside that table inside the JS inside the PHP echo then it won't print.

    When you say "it doesn't work," are you looking at your page, or the source of the page? My guess is that you are looking at the page itself, and not seeing your menu. If you look at the source, you'll probably see this for each menu item:

    <a href=""></a><br>

    If that's the case, then the problem is that your $menuxURL and $menuxLINK variables need to be declared global inside the function.

    Frankly, I think you are making this too complex. If all the function does is return text, then simply assign that text directly to $menuhtml, rather than call the function. Then you don't have to worry about variable scope.

      I didn't paste that part of the code but the variables are in fact declared globally so when I say that it doesn't work I mean that NOTHING comes up, neither in the html code source nor in the page, just plain nothing in place of where the menu should be

        instead of:

        return echo'balblabla';

        could you do:

        echo 'blabla bla';

          what do you mean? I don't do an echo return anywhere

            Originally posted by marcnyc
            what do you mean? I don't do an echo return anywhere

            ah sorry, my bad, I misread.

              so are there any other suggestions as to what I might be doing wrong with my approach?

                The only thing I can think of is this: if $b work normally and $menuhtml doesn't, the only difference between the two is that $b is assigned normally (passed through an URL or assigned by a $b = "value"; action) and $menuhtml is the result of an function... So I guess we'd have to find a way to sort of "freeze" the value of $menuhtml and store it as if it was a normally assigned variable... Is there any such way?

                  You really don't need a function just to return text. It would be a lot easier to read and debug if written this way:

                  <?php
                  $menuhtml = '<br>
                  	          <a href="'.$menu0URL.'">'.$menu0LINK.'</a> <br>
                  	          <a href="'.$menu1URL.'">'.$menu1LINK.'</a> <br>
                  	          <a href="'.$menu2URL.'">'.$menu2LINK.'</a> <br>
                  	          <a href="'.$menu3URL.'">'.$menu3LINK.'</a> <br>
                  	          <a href="'.$menu4URL.'">'.$menu4LINK.'</a> <br>
                  	          <a href="'.$menu5URL.'">'.$menu5LINK.'</a> <br>
                  	          <a href="'.$menu6URL.'">'.$menu6LINK.'</a> <br> ';
                  ?>
                  	<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
                  	<!--
                  	if (!useRedirect) {    // if dynamic embedding is turned on
                  		if(hasRightVersion) {  // if we detected an acceptable version
                  		  var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="339" height="284">\'
                  		  + '  <param name="movie" value="menu.swf?phpself=<?=$_SERVER["PHP_SELF"]?>&b=<?=$b?>">'
                  		  + '  <param name="quality" value="high">'
                  		  + '  <embed src="menu.swf?phpself=<?=$_SERVER["PHP_SELF"]?>&b=<?=$b?>" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="339" height="284"></embed>'
                  		  + '</object>';
                  		  document.write(oeTags);   // embed the flash movie
                  		} else {  // flash is too old or we cannot detect the plugin
                  		  // NOTE: height, width are required!
                  		  var alternateContent = '<table width="339" height="284"  border="0" cellpadding="0" cellspacing="0"><tr><td><font size="2"><b><div align="right"><?=$menuhtml?></div></font></b></td></tr></table>';
                  		  document.write(alternateContent);  // insert non-flash content
                  		}
                  	}	
                  	// -->
                  	</SCRIPT>
                  

                    Thank you very much for your contribution to this post dnast...
                    unfortunately my JS code has to be inside an PHP echo function becuase it will only be printed if a certain PHP IF statement is true... you know what I mean?

                    I also noticed your syntax <? =$b ?>...
                    I never saw that syntax with the equal sign... what is that? just curious so I know...

                      by the way I just thought of a workaround... I tested it and it works, so unless somebody else has a way to make work the above I guess I'll have to go with this one...

                      I introduced a new variable called $flash and if $flash=="no" then I don't even echo the JS code, but because the JS code has to be called the first time to actually do the content swapping, istead of swapping content I replace the URL...
                      here it goes:

                      $menuhtml = menuhtml();
                      $menuhtml = str_replace('|','<br>',$menuhtml);
                      $title = $GET["title"];
                      $flash = $
                      GET["flash"];
                      if ( $flash == "no" ) {
                      echo '<table width="339" height="284" border="0" cellpadding="0" cellspacing="0"><tr><td><div align="right"><font size="2">please select:<b>'.$menuhtml.'</b></font></div></td></tr></table>
                      ';
                      } else {
                      echo '
                      <SCRIPT LANGUAGE="JavaScript" type="text/javascript">
                      <!--
                      if (!useRedirect) { // if dynamic embedding is turned on
                      if(hasRightVersion) { // if we detected an acceptable version
                      var oeTags = \'<object classid="clsid😃27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="339" height="284">\'
                      + \' <param name="movie" value="menu.swf?phpself='.$SERVER["PHP_SELF"].'&b='.$b.'">\'
                      + \' <param name="quality" value="high">\'
                      + \' <embed src="menu.swf?phpself='.$
                      SERVER["PHP_SELF"].'&b='.$b.'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="339" height="284"><\/embed>\'
                      + \'<\/object>\';
                      document.write(oeTags); // embed the flash movie
                      } else { // flash is too old or we cannot detect the plugin
                      // NOTE: height, width are required!
                      // var alternateContent = \'<table width="339" height="284" border="0" cellpadding="0" cellspacing="0"><tr><td><font size="2"><b><div align="right">'.$b.'you do NOT have the FREE Flash player plug in installed - please <a href="http://www.macromedia.com/go/getflashplayer">click here</a> to dowload it<br> alternatively you may use the menu at the bottom of these pages to navigate the website</div></font></b></td></tr></table>\';
                      // document.write(alternateContent); // insert non-flash content
                      window.location.replace("'.$_SERVER["PHP_SELF"].'?b='.$b.'&flash=no&title='.$title.'");
                      }
                      }
                      // -->
                      </SCRIPT>
                      ';
                      }

                      Hope this helps somebody out there

                        Originally posted by marcnyc
                        Thank you very much for your contribution to this post dnast...
                        unfortunately my JS code has to be inside an PHP echo function becuase it will only be printed if a certain PHP IF statement is true... you know what I mean?

                        I also noticed your syntax <? =$b ?>...
                        I never saw that syntax with the equal sign... what is that? just curious so I know...

                        It would still work outside of <? ?>. For example:

                        <?php
                        if (1 > 2) {
                        ?>
                        1 is greater than 2
                        <?php
                        } else {
                        ?>
                        1 is not greater than 2
                        <?php
                        }
                        

                        It would only print "1 is not greater than 2". However there is a more readable syntax for this.

                        And the <?=$var?> is just shorthand for <?php echo $var ?>. You'll see a short example towards the bottom of that link.

                        Anyway, I guess it doesn't matter since you got it working. Good luck on the rest of your site. 🙂

                          That's very clever! I should have thought about that myself, damnit! ;-)
                          Anyway, because I am eager to learn I did try your suggestion and it still doesn't work... I wanted to try to to know if it would work but I am afraid it doesn't, so unless somebody else has other clever ideas that are out of my league I'll stick to my workaround...
                          Thanks for all your help and support and lighting fast replies! This is exciting!

                            Marc,

                            Your problem is in your echo statement. You are delimiting the echo with the single quote ('), and you are also using single quotes in your javascript. That won't work. I recommend you use heredoc, or take all of the javascript out of the PHP code as dnast has suggested. However, I wouldn't use the shortcut syntax -- there's a good chance your server has shortcut tags disabled. So, simply use <?php echo $menuhtml; ?>.

                            If you want to use heredoc syntax, here is your code rewritten. I have tested on my server, and it does work (although in my case the menuxURL and menuxLINK variables are empty, and there is a Javascript error that might be due to incomplete code). The menuhtml() function DOES return the intended HTML:

                            <?php
                            function menuhtml() {
                            $retval = <<<EOS
                            |
                            <a href="$menu0URL">$menu0LINK</a> |
                            <a href="$menu1URL">$menu1LINK</a> |
                            <a href="$menu2URL">$menu2LINK</a> |
                            <a href="$menu3URL">$menu3LINK</a> |
                            <a href="$menu4URL">$menu4LINK</a> |
                            <a href="$menu5URL">$menu5LINK</a> |
                            <a href="$menu6URL">$menu6LINK</a> |
                            EOS;
                            return $retval;
                            }
                            $menuhtml = menuhtml();
                            $menuhtml = str_replace('|','<br>',$menuhtml);
                            $phpself = $_SERVER['PHP_SELF'];
                            echo <<<EOS
                            <SCRIPT LANGUAGE="JavaScript" type="text/javascript">
                            <!--
                            if (!useRedirect) { // if dynamic embedding is turned on
                            if(hasRightVersion) { // if we detected an acceptable version
                            var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="339" height="284">'
                            + ' <param name="movie" value="menu.swf?phpself=$phpself&b=$b">'
                            + ' <param name="quality" value="high">'
                            + ' <embed src="menu.swf?phpself=$phpself&b=$b" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="339" height="284"><\/embed>'
                            + '<\/object>';
                            document.write(oeTags); // embed the flash movie
                            } else { // flash is too old or we cannot detect the plugin
                            // NOTE: height, width are required!
                            var alternateContent = '<table width="339" height="284" border="0" cellpadding="0" cellspacing="0"><tr><td><font size="2"><b><divalign="right">$menuhtml</div></font></b></td></tr></table>';
                            document.write(alternateContent); // insert non-flash content
                            }
                            }
                            // -->
                            </SCRIPT>
                            EOS;
                            ?>

                              Altough I have successfully used the heredoc syntax in the past and did try to apply it to this problem a few days before posting here, I couldn't get it to work...
                              I just tried your example (I copied and pasted) and I get parsing errors... Is it possible that my local installation of PHP on Mac OSX has something set so that the use of the heredoc syntax is made impossible?

                                Unfortunately, copy/paste won't work. PHPBuilder adds a space at the end of each line, so there is a space in the line:

                                EOS;

                                If there is ANYTHING, including a space, after that semicolon, heredoc syntax won't work. Remove the space, and you should be ok.

                                  you were right, there was a space resulted from the pasting, but even after removing all the spaces I still get parse errors

                                    Write a Reply...