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

  • SEARCH
  • Home
  • 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: Safest Way to Loop Over Javascript Object I have this hard coded
Possible Duplicate: Subtract days from a date in javascript I have got a JavaScript
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Objective C for Windows iPhone development on Windows Is there any way
Possible Duplicate: JavaScript: why does parseInt(1/0, 19) return 18? Why does parseInt(1/0, 19) evaluate
Possible Duplicate: get current latitude and longitude from gps enabled device I use the
Possible Duplicate: How to convert text to unicode code point like \u0054\u0068\u0069\u0073 using php?
Possible Duplicate: How to read Windows loged in username with PHP/IIS I'm work on

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.