Jump to content

using javasript function in php


pellio

Recommended Posts

hi im using a javascript function from jquery in a php page. im getting the following error:

 

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/cabingla/public_html/interface/templates/Modern-Side-Navigation.php on line 50

 

 

any ideas what im doing wrong?? cheers

 

here is the html code of page:

 

 

<body>

 

<a name="top"></a>

 

<div id="container">

 

<div id="head">

 

<div id="headlogo">

<h1><a href="/index.php" accesskey="1" title="<? echo $company_name; ?> - Home Page"><? if(file_exists($sitelogo)){echo '<span class="hide">';} else {} ?><? echo $company_name; ?><? if(file_exists($sitelogo)){echo '</span>';} else {} ?></a></h1>

</div> <!-- end of headlogo -->

 

<div id="imagestrip" title="Theme Nights">

 

 

<div id="images">

 

 

<?

//*************images***************

 

if (($page==$default_page)&&($home_random_images=="yes")) {

$altimage2 = $company_name;

$path = "content/images/";

$dir = opendir($path."thumb/");

while (($file = readdir($dir)) !== false) {

if (($file == ".")||($file == "..")||($file == ".thumbs")) {}

          else { $files[] = $file; }

      }

closedir($dir);

 

if ($files) {

srand ((double) microtime( )*1000000);

$random_number = rand(0,count($files)-1);

 

for($i=0; $i<$max_thumbs; $i++)

{

if ($random_number > count($files)-1) {$random_number=0;}

$smallimagefile = "/".$path."thumb/".$files[$random_number];

$bigimagefile = "/".$path."big/".$files[$random_number];

 

echo '

 

 

 

 

<script type="text/javascript" id="source-test2">

$(function() {

$('#test2').crossSlide({

  sleep: 2, //in sec

  fade: 1  //in sec

}, [

  { src: 'topimages-v1.jpg'},

  { src: 'topimages-v2.jpg' }

]);

});

</script> ';

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

}

}

}

else {

if ($page) {$pageimage = $page;}

if ($subpage) {$subpageimage = "-".$subpage;}

$imagefile = $pageimage.$subpageimage;

$imagefile = preg_replace("/ /i", "-", $imagefile);

$imagefile = "content/.system-use/imagefiles/".$imagefile.".inc";

if (file_exists($imagefile)) {

require $imagefile;

$d = 1;

while ($d < $max_thumbs+1) {

$image = 'content/images/thumb/'.${"image".$d};

$bigimage = 'content/images/big/'.${"image".$d};

$altimage = $company_name." - ".${"imagedescription".$d};

 

if (file_exists($image)) {

echo '

<span class="topimage"><a onclick="MM_openBrWindow(\'/popupimage.php?imagefile='.$bigimage.'&imagedesc='.$altimage.'\',\'picwin\',\'scrollbars=no,width=100,height=100\'); return false;" href="/popupimage.php?imagefile='.$bigimage.'&imagedesc='.$altimage.'" target="_blank" ><img src="/'.$image.'" alt="'.$altimage.'"  class="imagethumb" height="160" width="235" /></a></span>';}

    $d++;

}}}

//*************END images***************

?>

</div>

 

 

 

 

</div> <!-- end of imagestrip -->

 

 

</div><!-- end of head -->

 

 

 

 

 

 

<div id="nav" class="printhide">

 

<div id="navlist">

 

<ul>

<?php

 

$pagepath = "content/pages/";

$legalpath = "content/legals/";

 

$mainnavpath = "content/.system-use/navigation/";

$mainnavfile = $mainnavpath."mainnav.inc";

if (file_exists($mainnavfile)) {

require $mainnavfile;

 

 

sort ($mainfiles);

 

 

for($i=0; $i<count($mainfiles); $i++)

{

if (!preg_match("/XX-/",$mainfiles[$i])) {

$displayname = preg_replace("/\.inc/i", "", $mainfiles[$i]);

$displayname = substr($displayname, 3);

echo "<li";

if ($page==$displayname) {echo ' class="lion"';}

echo "><a title='$displayname' href='";

if ($useredirect=="yes"){echo '/'.$displayname.'/';} else {echo '/index.php?page='.$displayname;}

echo"' ";

if ($page==$displayname) {echo 'class="aon"';} else {}

echo ">$displayname</a></li>\n";

 

//*******now check and see if any sub-menus******

if ($page==$displayname) {

 

$subnavfile = $mainnavpath.$displayname.".inc";

if (file_exists($subnavfile)) {

require $subnavfile;

sort ($subfiles);

for($j=0; $j<count($subfiles); $j++)

{

if (!preg_match("/XX-/",$subfiles[$j])) {

$subdisplayname = preg_replace("/\.inc/i", "", $subfiles[$j]);

$subdisplayname = substr($subdisplayname, 3);

echo "<li class='";

if ($subpage==$subdisplayname) {echo "li2on";}else {echo "li2";}

echo "'><a title='$subdisplayname' href='";

if ($useredirect=="yes"){echo '/'.$displayname.'/'.$subdisplayname;} else {echo '/index.php?page='.$displayname.'&subpage='.$subdisplayname;}

echo "' ";

if ($subpage==$subdisplayname) {echo 'class="aon"';} else {}

echo ">$subdisplayname</a></li>\n";

}}

}else {}

}

//************end sub menus***********************

 

} }

}

 

else { echo "<strong>No Navigation - Please Login to your Admin System and set the Page Order</strong>"; }

 

?>

<?

// Show Price List Link in Menu

if ($showpricelist == "yes") {

echo "<li";

if ($page=='Price List') {echo ' class="lion"';}

echo "><a title='Price List' href='";

if ($useredirect=="yes"){echo '/Price List/';} else {echo '/index.php?page=Price List';}

echo"' ";

if ($page=='Price List') {echo 'class="aon"';} else {}

echo ">Price List</a></li>\n";

 

}

?>

</ul>

 

</div>

 

</div>

 

 

 

<div id="content">

 

 

 

 

 

 

 

 

<div class="crumbs">

<?

            if ($show_crumbs=="yes") {

echo "You are here :: <a href='";

if ($useredirect=="yes"){echo '/'.$page.'/';} else {echo '/index.php?page='.$page;}

echo "'>".$page."</a>";

if ($subpage) { echo " :: <a href='";

if ($useredirect=="yes"){echo '/'.$page.'/'.$subpage;} else {echo '/index.php?page='.$page.'&subpage='.$subpage;}

echo "'>" . $subpage ."</a>";}

            }

 

?>

 

<span style="text-align:right; display:block; float:right;"> <? include "cart/phpCart_minibasket.php"; ?></span>

</div>

 

 

<br />

<a name='content'></a>

 

<?

//*************If Homepage - Show the news***************

$newslocation = explode("|", $show_news);

if (($page==$newslocation[0])&&($subpage==$newslocation[1])) {

echo "<div id='news'>";

echo "<h4>Latest News</h4>";

include("admin/newsmanager/news.php");

echo "</div>";

}

//*************End News**********************************

?>

 

 

<h1><?

if ($subpage) {$titlename=$subpage;} else {$titlename=$page;}

echo $titlename;

?></h1>

 

 

<div class="offersdiv">

<a href="#"><img src="/content/images/misc/freewine.gif" alt="Free wine when you join our email list!" /></a><br /><br />

<a href="#"><img src="/content/images/misc/recommend.gif" alt="Recommend This Site To a Friend" /></a>

 

 

 

</div>

 

 

 

 

 

 

<?

 

if ($page) {$incfile = $pagepath.$page.'.inc';}

if ($subpage) {$incfile = $pagepath.$page.'/'.$subpage.'.inc';}

if (($page=="Legal")&&(!$subpage)) {$subpage="Privacy Policy";}

if ($page=="Legal") {$incfile = $legalpath.$subpage.'.inc';}

if ($page=="Shopping Cart") { $incfile = 'cart/phpCart_basket.php';}

if ($page=="Shopping Checkout") { $incfile = 'cart/phpCart_checkout.php';}

if ($page=="Order Received") { $incfile = 'cart/order_received.php';}

if ($page=="Price List") { $incfile = 'cart/phpCart_shop.php';}

 

 

if (file_exists($incfile)) {

require $incfile;

}

else { echo $incfile;

echo "<br /><br /><h4>Error - No page.  Please advise webmaster.</h4>";

}

 

 

?>

 

<?

 

//******* LOAD CUSTOM MODULES BASED ON PAGE ASSIGNMENT ****

 

//*********Image Gallery*******

$gallerylocation = explode("|", $imagegallery);

if (($page==$gallerylocation[0])&&($subpage==$gallerylocation[1])) {

$galleryfile = 'imagegallery/iframe.php';

require $galleryfile;

}

//*****************************

 

//*********Contact Form*******

$contactformlocation = explode("|", $contactform);

if (($page==$contactformlocation[0])&&($subpage==$contactformlocation[1])) {

$contactfile = 'interface/contactform.php';

require $contactfile;

}

//*****************************

 

?>

 

 

 

 

<div style="clear: both"> </div>

 

 

 

 

 

 

</div><!-- end of content -->

 

 

<br class="clear" />

 

 

 

<a href="#top" class="printhide">Back to Top</a>

 

 

 

 

 

</div><!-- end of container -->

 

 

<div id="footer">

 

<div class="footerbox">

 

 

 

 

 

<div class="footerlinks">

<a href="mailto:<? echo $company_email ;?>" title="Email Us" accesskey="0">Email Us</a>

|

<a href="<? if ($useredirect=="yes"){echo '/Legal/Privacy Policy';} else {echo '/index.php?page=Legal&subpage=Privacy Policy';} ?>" title="Privacy Policy" accesskey="2">Privacy Policy</a>

|

<a href="<? if ($useredirect=="yes"){echo '/Legal/Terms and Conditions';} else {echo '/index.php?page=Legal&subpage=Terms and Conditions';} ?>" title="Terms and Conditions" accesskey="3">Terms & Conditions</a>

|

<a href="<? if ($useredirect=="yes"){echo '/Legal/Accessibility';} else {echo '/index.php?page=Legal&subpage=Accessibility';} ?>" title="Accessibility Statement" accesskey="4">Accessibility</a>

<? if ($show_sitemap=="yes") {

echo ' | <a href="';

if ($useredirect=="yes"){echo '/Legal/Site Map';} else {echo '/index.php?page=Legal&subpage=Site Map';}

echo '" title="Site Map" accesskey="5">Site Map</a>';

} ?>

<? if ($show_search=="yes") {

echo ' | <a href="';

if ($useredirect=="yes"){echo '/Legal/Site Search';} else {echo '/index.php?page=Legal&subpage=Site Search';}

echo '" title="Site Search" accesskey="6">Search</a>';

} ?>

</div>

 

 

<div id="copyright">

<? require "interface/poweredby.php"; ?>

<br />Copyright <? echo $company_name ;?>

</div>

 

 

 

</div>

 

 

 

 

</div><!-- end of footer -->

 

 

 

 

 

<a href="#top" class="hide" title='Back to Top'>Back to Top</a>

 

 

 

</body>

Link to comment
https://forums.phpfreaks.com/topic/135313-using-javasript-function-in-php/
Share on other sites

First, please use the [code][/code] tags when posting code

 

PHP cannot parse Javascript. Javascript is client-side, PHP is server-side. Everything PHP does is done before the data is returned to the browser from the server.

 

If you simply want to echo the javascript from PHP, escape any quote's in the javascript.

Please, when posting put all of your code inside the code brackets so we can easily see all of the code.

 

<body>

   <a name="top"></a>

   <div id="container">

      <div id="head">

         <div id="headlogo">
            <h1><a href="/index.php" accesskey="1" title="<? echo $company_name; ?> - Home Page"><? if(file_exists($sitelogo)){echo '<span class="hide">';} else {} ?><? echo $company_name; ?><? if(file_exists($sitelogo)){echo '</span>';} else {} ?></a></h1>
         </div> <!-- end of headlogo -->

         <div id="imagestrip" title="Theme Nights">


<div id="images">


         <?
         //*************images***************

      if (($page==$default_page)&&($home_random_images=="yes")) {
                     $altimage2 = $company_name;
                  $path = "content/images/";
                  $dir = opendir($path."thumb/");
                  while (($file = readdir($dir)) !== false) {
                  if (($file == ".")||($file == "..")||($file == ".thumbs")) {}
                       else {    $files[] = $file; }
                                                   }
                  closedir($dir);

   if ($files) {
srand ((double) microtime( )*1000000);
$random_number = rand(0,count($files)-1);

                  for($i=0; $i<$max_thumbs; $i++)
                  {
                  if ($random_number > count($files)-1) {$random_number=0;}
                  $smallimagefile = "/".$path."thumb/".$files[$random_number];
                  $bigimagefile = "/".$path."big/".$files[$random_number];

   echo '
      



<script type="text/javascript" id="source-test2">
$(function() {
$('#test2').crossSlide({
  sleep: 2, //in sec
  fade: 1   //in sec
}, [
  { src: 'topimages-v1.jpg'},
  { src: 'topimages-v2.jpg' }
]);
});
</script> ';

















                  }
                  }
                  }
   else {
         if ($page) {$pageimage = $page;}
         if ($subpage) {$subpageimage = "-".$subpage;}
         $imagefile = $pageimage.$subpageimage;
         $imagefile = preg_replace("/ /i", "-", $imagefile);
         $imagefile = "content/.system-use/imagefiles/".$imagefile.".inc";
         if (file_exists($imagefile)) {
         require $imagefile;
         $d = 1;
         while ($d < $max_thumbs+1) {
         $image = 'content/images/thumb/'.${"image".$d};
         $bigimage = 'content/images/big/'.${"image".$d};
         $altimage = $company_name." - ".${"imagedescription".$d};

         if (file_exists($image)) {
         echo '
               <span class="topimage"><a onclick="MM_openBrWindow(\'/popupimage.php?imagefile='.$bigimage.'&imagedesc='.$altimage.'\',\'picwin\',\'scrollbars=no,width=100,height=100\'); return false;" href="/popupimage.php?imagefile='.$bigimage.'&imagedesc='.$altimage.'" target="_blank" ><img src="/'.$image.'" alt="'.$altimage.'"  class="imagethumb" height="160" width="235" /></a></span>';}
    $d++;
}}}
   //*************END images***************
?>
</div>




         </div> <!-- end of imagestrip -->


      </div><!-- end of head -->



      


<div id="nav" class="printhide">

<div id="navlist">

<ul>
<?php

         $pagepath = "content/pages/";
         $legalpath = "content/legals/";

         $mainnavpath = "content/.system-use/navigation/";
         $mainnavfile =    $mainnavpath."mainnav.inc";
         if (file_exists($mainnavfile)) {
         require $mainnavfile;


         sort ($mainfiles);


               for($i=0; $i<count($mainfiles); $i++)
               {
               if (!preg_match("/XX-/",$mainfiles[$i])) {
               $displayname = preg_replace("/\.inc/i", "", $mainfiles[$i]);
               $displayname = substr($displayname, 3);
               echo "<li";
                if ($page==$displayname) {echo ' class="lion"';}
               echo "><a title='$displayname' href='";
               if ($useredirect=="yes"){echo '/'.$displayname.'/';} else {echo '/index.php?page='.$displayname;}
               echo"' ";
               if ($page==$displayname) {echo 'class="aon"';} else {}
               echo ">$displayname</a></li>\n";

               //*******now check and see if any sub-menus******
               if ($page==$displayname) {

               $subnavfile =    $mainnavpath.$displayname.".inc";
               if (file_exists($subnavfile)) {
               require $subnavfile;
               sort ($subfiles);
               for($j=0; $j<count($subfiles); $j++)
               {
                  if (!preg_match("/XX-/",$subfiles[$j])) {
                  $subdisplayname = preg_replace("/\.inc/i", "", $subfiles[$j]);
                  $subdisplayname = substr($subdisplayname, 3);
                  echo "<li class='";
                  if ($subpage==$subdisplayname) {echo "li2on";}else {echo "li2";}
                  echo "'><a title='$subdisplayname' href='";
                  if ($useredirect=="yes"){echo '/'.$displayname.'/'.$subdisplayname;} else {echo '/index.php?page='.$displayname.'&subpage='.$subdisplayname;}
                  echo "' ";
                  if ($subpage==$subdisplayname) {echo 'class="aon"';} else {}
                  echo ">$subdisplayname</a></li>\n";
                     }}
               }else {}
               }
               //************end sub menus***********************

            }   }
         }

         else { echo "<strong>No Navigation - Please Login to your Admin System and set the Page Order</strong>"; }

?>
<?
// Show Price List Link in Menu
if ($showpricelist == "yes") {
   echo "<li";
                if ($page=='Price List') {echo ' class="lion"';}
               echo "><a title='Price List' href='";
   if ($useredirect=="yes"){echo '/Price List/';} else {echo '/index.php?page=Price List';}
   echo"' ";
               if ($page=='Price List') {echo 'class="aon"';} else {}
               echo ">Price List</a></li>\n";

}
?>
</ul>

</div>

</div>



      <div id="content">








<div class="crumbs">
         <?
            if ($show_crumbs=="yes") {
         echo "You are here :: <a href='";
         if ($useredirect=="yes"){echo '/'.$page.'/';} else {echo '/index.php?page='.$page;}
         echo "'>".$page."</a>";
         if ($subpage) { echo " :: <a href='";
   if ($useredirect=="yes"){echo '/'.$page.'/'.$subpage;} else {echo '/index.php?page='.$page.'&subpage='.$subpage;}
         echo "'>" . $subpage ."</a>";}
            }

         ?>

         <span style="text-align:right; display:block; float:right;">   <? include "cart/phpCart_minibasket.php"; ?></span>
         </div>


<br />
   <a name='content'></a>

<?
//*************If Homepage - Show the news***************
$newslocation = explode("|", $show_news);
if (($page==$newslocation[0])&&($subpage==$newslocation[1])) {
echo "<div id='news'>";
echo "<h4>Latest News</h4>";
include("admin/newsmanager/news.php");
echo "</div>";
}
//*************End News**********************************
?>


<h1><?
if ($subpage) {$titlename=$subpage;} else {$titlename=$page;}
echo $titlename;
?></h1>


<div class="offersdiv">
<a href="#"><img src="/content/images/misc/freewine.gif" alt="Free wine when you join our email list!" /></a><br /><br />
<a href="#"><img src="/content/images/misc/recommend.gif" alt="Recommend This Site To a Friend" /></a>



</div>






<?

         if ($page) {$incfile = $pagepath.$page.'.inc';}
         if ($subpage) {$incfile = $pagepath.$page.'/'.$subpage.'.inc';}
         if (($page=="Legal")&&(!$subpage)) {$subpage="Privacy Policy";}
         if ($page=="Legal") {$incfile = $legalpath.$subpage.'.inc';}
         if ($page=="Shopping Cart") { $incfile = 'cart/phpCart_basket.php';}
         if ($page=="Shopping Checkout") { $incfile = 'cart/phpCart_checkout.php';}
         if ($page=="Order Received") { $incfile = 'cart/order_received.php';}
         if ($page=="Price List") { $incfile = 'cart/phpCart_shop.php';}


         if (file_exists($incfile)) {
         require $incfile;
         }
         else { echo $incfile;
         echo "<br /><br /><h4>Error - No page.  Please advise webmaster.</h4>";
         }


         ?>

         <?

         //******* LOAD CUSTOM MODULES BASED ON PAGE ASSIGNMENT ****

         //*********Image Gallery*******
               $gallerylocation = explode("|", $imagegallery);
               if (($page==$gallerylocation[0])&&($subpage==$gallerylocation[1])) {
               $galleryfile = 'imagegallery/iframe.php';
               require $galleryfile;
               }
         //*****************************

         //*********Contact Form*******
               $contactformlocation = explode("|", $contactform);
               if (($page==$contactformlocation[0])&&($subpage==$contactformlocation[1])) {
               $contactfile = 'interface/contactform.php';
               require $contactfile;
               }
         //*****************************

         ?>




<div style="clear: both"> </div>






      </div><!-- end of content -->


      <br class="clear" />



      <a href="#top" class="printhide">Back to Top</a>


      


   </div><!-- end of container -->


<div id="footer">

<div class="footerbox">





<div class="footerlinks">
      <a href="mailto:<? echo $company_email ;?>" title="Email Us" accesskey="0">Email Us</a>
       |
      <a href="<? if ($useredirect=="yes"){echo '/Legal/Privacy Policy';} else {echo '/index.php?page=Legal&subpage=Privacy Policy';} ?>" title="Privacy Policy" accesskey="2">Privacy Policy</a>
       |
      <a href="<? if ($useredirect=="yes"){echo '/Legal/Terms and Conditions';} else {echo '/index.php?page=Legal&subpage=Terms and Conditions';} ?>" title="Terms and Conditions" accesskey="3">Terms & Conditions</a>
       |
      <a href="<? if ($useredirect=="yes"){echo '/Legal/Accessibility';} else {echo '/index.php?page=Legal&subpage=Accessibility';} ?>" title="Accessibility Statement" accesskey="4">Accessibility</a>
      <? if ($show_sitemap=="yes") {
      echo ' | <a href="';
      if ($useredirect=="yes"){echo '/Legal/Site Map';} else {echo '/index.php?page=Legal&subpage=Site Map';}
      echo '" title="Site Map" accesskey="5">Site Map</a>';
      } ?>
      <? if ($show_search=="yes") {
      echo ' | <a href="';
      if ($useredirect=="yes"){echo '/Legal/Site Search';} else {echo '/index.php?page=Legal&subpage=Site Search';}
      echo '" title="Site Search" accesskey="6">Search</a>';
      } ?>
</div>


<div id="copyright">
<? require "interface/poweredby.php"; ?>
<br />Copyright <? echo $company_name ;?>
   </div>



</div>




   </div><!-- end of footer -->



   

      <a href="#top" class="hide" title='Back to Top'>Back to Top</a>



</body>

 

It apears that you have not back-slashed any of the javascript which is inside the php code. You will need to look through the code and find any commas which are inside the php code and and put a simple \ before them

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.