Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7018657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:04:49+00:00 2026-05-27T23:04:49+00:00

Possible Duplicate: What is the safest way of passing arguments from server-side PHP to

  • 0

Possible Duplicate:
What is the safest way of passing arguments from server-side PHP to client-size JavaScript

Goal: Replace the static file name in the javascript object with php data .

Problem:

I don’t know if I my syntax or logic is right as I am not getting any js or php errors. Worst of all my script is not giving the desired results. You can see the actual page at
http://www.iamvishal.com/dev/property/burradon-road-burradon line 197

javascript object which I want to make using php:

var data = { 'JPEG/1.jpg': { caption: '' }, 'JPEG/2.jpg': { caption: '' }, 'JPEG/3.jpg': 
{ caption: '' }, 'JPEG/4.jpg': { caption: '' },  'JPEG/5.jpg': { caption: '' },  
'JPEG/6.jpg': { caption: '' },
'JPEG/7.jpg': { caption: '' },  'JPEG/8.jpg': { caption: '' },};

So I need to replace JPEG/1.JPG with a php variable $filename. Below is my code.

<script type="text/javascript">

var data = { ;


<?php
$queryglob ="JPEG/*".$node->field_ropertyid['und'][0]['value'].".jpg";
// Here I am getting all the file names as per my condition.

foreach (glob($queryglob) as $filename) {
// here I am want each file name to be assigned into the javascript object
?>

data = data+'+<?php print $filename ; ?> +':{caption:''}, ;
<?php

}
?>

data = data+};

</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:04:49+00:00Added an answer on May 27, 2026 at 11:04 pm

    Why you are not using json_encode

    <?php
     $data = array( );
     foreach (glob($queryglob) as $filename) $data[$filename] = array( 'caption' => '' );
    ?>
    <script type="text/javascript">
     var data = <?php echo json_encode( $data ); ?>
    </script>
    

    That is much more clever than building a string

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Easiest way to echo HTML in PHP? Hello, one simple and short
Possible Duplicate: Best way to stop SQL Injection in PHP If I were to
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} What's the
Possible Duplicate: Singleton: How should it be used Following on from Ewan Makepeace 's
Possible Duplicate: How to horizontally center a div? One simple way to make an
Possible Duplicate: Resetting a multi-stage form with jQuery Once the form submitted, response from
Possible Duplicate: Reading through file using ifstream I'm trying to find a way to
Possible Duplicate: How would I identify if a website originates from a mobile browser?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.