Eliminating raw code being displayed in variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
elinews
Forum Commoner
Posts: 38
Joined: Tue Aug 14, 2007 7:18 pm

Eliminating raw code being displayed in variable

Post by elinews »

I made this javascript, which is printing a js array, a php variable ($java) :

Code: Select all

<script type='text/javascript'> 

document.write(photo[0]) 

</script>
I am then inserting that variable into another like this:

Code: Select all

$image="$dir/$java";

This is creating the source for the image. And of course it outputs the full javascript code instead of printing the array when it is called upon in $image.

My question is how do I get the array name to show instead of the javascript code? I'm thinking it must be done with a function() . . .



This is how I'm using it:

Code: Select all

//Gets the width and height of the image and outputs it
$theimage = getimagesize($image);
$width = $theimage[0];
$height = $theimage[1];
After that I'm using an if else statement to resize the image if it's width and height exceed a certain amount. However when searching for image it looks for eg. http://website.com/images/<script type='text/javascript'>
document.write(photo[0])
</script>

as oppose to (what I want) http://website.com/images/photo1.jpg
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

It sounds like you want to send JavaScript to PHP. You can't.

Even if you look at it, document.write writes TO the document. That's it. It only affects the DOM.
elinews
Forum Commoner
Posts: 38
Joined: Tue Aug 14, 2007 7:18 pm

Post by elinews »

Hmm... Ok how about this - is there a way I could include a variable in a new variables name?

Example

Code: Select all

$number="4";


$image4=$file;   //with "4" coming from the variable $number
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Yes, variable variables.

Code: Select all

$number = 4;
${'image'.$number} = $file

//echo $image4
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You've already got a thread on this subject elinews. Locked.
Locked