How to add PHP inside a script?

Discussion in 'PHP' started by Jboo, Oct 16, 2008.

  1. #1
    Hi, can anyone tell me how to add the php that I've added to the line starting var ch_queries so that the script still works (at the moment it breaks).

    Thanks for any help.

    <script type="text/javascript"><!--
    ch_font_title = "Verdana";
    ch_font_text = "Verdana";
    var ch_queries = new Array( "<?php if (content_format('field_ad_text', $field_ad_text[0]) != '') : ?>
      <?php foreach ($field_ad_text as $ad_text) { ?>
        <?php print content_format('field_ad_text', $ad_text) ?>
      <?php } ?>
    <?php endif; ?>" );
    var ch_selected=Math.floor((Math.random()*ch_queries.length));
    if ( ch_selected < ch_queries.length ) {
    ch_query = ch_queries[ch_selected];
    }
    //--></script>
    <script  src="http://scripts.chitika.net/eminimalls/amm.js" type="text/javascript">
    </script>
    Code (markup):
     
    Jboo, Oct 16, 2008 IP
  2. FredL

    FredL Peon

    Messages:
    14
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    <script type="text/javascript"><!--
    ch_font_title = "Verdana";
    ch_font_text = "Verdana";
    
    var ch_queries = [];
    <?php if (content_format('field_ad_text', $field_ad_text[0]) != '') : ?>
      <?php foreach ($field_ad_text as $ad_text) : ?>
        ch_queries.push(<?php echo content_format('field_ad_text', $ad_text) ?>);
      <?php endforeach; ?>
    <?php endif; ?>
    
    var ch_selected=Math.floor((Math.random()*ch_queries.length));
    if ( ch_selected < ch_queries.length ) {
    ch_query = ch_queries[ch_selected];
    }
    //--></script>
    <script  src="http://scripts.chitika.net/eminimalls/amm.js" type="text/javascript">
    </script>
    
    PHP:
    Try this one.
     
    FredL, Oct 16, 2008 IP