My Computer Forum Computer Science Forum

Go Back   My Computer Forum > Computer Science Forum > Programming

Programming Programming Languages, Interpreters, and Compilers - Assembly, Declarative, Machine, Object Oriented, Iterative


Reply
 
LinkBack Thread Tools Display Modes
August 26th, 2012, 06:07 AM   #1
 
Joined: Aug 2012
Posts: 2
Answer of an query in an array?

Below the script is not working, how can I slove this?

<?$short="file.php"?>


<?
$filename = 'docs/$short';

if (file_exists($filename)) {
echo "Yes $short";
} else {
echo "No $short";
}
?>

Thanks already

HannoD
HannoD is offline  
 

My Computer Forum is free to register and we welcome everyone!

August 26th, 2012, 10:48 AM   #2
Site Founder
 
julien's Avatar
 
Joined: Dec 2007
Posts: 414
Re: Answer of an query in an array?

Hello,

Could you please give us the PHP message error you got in return ? That would help determining where lies the bug ...
julien is offline  
August 26th, 2012, 02:11 PM   #3
 
Joined: Aug 2012
Posts: 2
Re: Answer of an query in an array?

It doesn't give an error message, it says No $short.

if I write
$filename = 'docs/file.php'; then it tells Yes

The problem is that there possible not twice a $ in the line allowed like $filename = 'docs/$short';

By the way the file does exists!
HannoD is offline  
September 1st, 2012, 08:09 AM   #4
Site Founder
 
julien's Avatar
 
Joined: Dec 2007
Posts: 414
Re: Answer of an query in an array?

The problem lies within the parsing of your string.
When you use single quotes, php variables are not parsed (i.e. they are interpreted as part of the string characters).
If you use double quotes, php variables will be parsed within your string: try using double quotes rather than single quotes in order to parse your $short variable.

$filename = "docs/$short'';

If this still doesn't work, try:
$filename = 'docs/'.$short;
julien is offline  
Reply

  My Computer Forum > Computer Science Forum > Programming

Tags
answer, array, query



Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
what will be the correct answer ? jumbo123 Computer Science 4 July 11th, 2012 03:06 AM
Verifying that a SQL query has executed correctly julien Web Databases 0 April 22nd, 2012 02:30 PM
Array problem cybercolt Databases 2 June 16th, 2011 05:10 AM





Copyright © 2018 My Computer Forum Forum. All rights reserved.