top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

why ${0} is valid but ${0 is not valid in PHP

0 votes
425 views

Why ${0} is valid but ${0 is not valid? it means that curly braces evaluate what's inside them and that's why we
cannot have ${0?

Variables shouldn't start from 0 so it means that it started from braces? if yes why I cannot have ${0? and what is the variable here finally? $0 is what it interprets? if yes so it is not a legal variable.

posted Aug 24, 2014 by Honey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

The variable ${0} is a variable variable. For instance:

$foo = 50;
$fee = 'foo';
echo ${$fee}."n"; // This will output 50.
echo ${'foo'}."n"; // Again this will out 50.

To leave off the closing curly brace is to leave the expression unterminated. Similar to leaving off a parenthesis, square brace, or conditional brace. The engine needs to know the end of the variable to which it should retrieve it's value to then find the actual variable to look up in the current context.

answer Aug 25, 2014 by Luv Kumar
Similar Questions
+1 vote

I'm adding some minification to our cache.class.php and am running into an edge case that is causing me grief.

I want to remove all comments of the // variety, HOWEVER I don't want to remove URLs...

Given some example text here with carefully crafted cases:

// another comment here

function bookmarksite(title,url){
 if (window.sidebar) // firefox
 window.sidebar.addPanel(title, url, "");
 else if(window.opera &
 elem.setAttribute('href',url);
 elem.setAttribute('title',title);
 elem.setAttribute('rel','sidebar');
 elem.click();
 } 
 else if(document.all)// ie
 window.external.AddFavorite(url, title);
}

I've tried so many variations and hunted on StackOverflow, Google, etc. and what would seem like a task already solved, doesn't seem to be.

This is "close", but still matches //foo.com (omitting the : of course)

s*(?!:)//.*?$ (count it as '/m' multiline)

This ultimately ends up in a PHP line of code like so:

$sBlob = preg_replace("@s*//.*?$@m",'',$sBlob);

Here are some other links of stuff I've found and tried to experiment with varying degrees.

http://stackoverflow.com/questions/4568410/match-comments-with-regex-but-not-inside-a-quote
http://stackoverflow.com/questions/611883/regex-how-to-match-everything-except-a-particular-pattern
http://stackoverflow.com/questions/11863847/regex-to-match-urls-but-not-urls-in-hyperlinks
http://stackoverflow.com/questions/643113/regex-to-strip-comments-and-multi-line-comments-and-empty-lines

0 votes

I've recently discovered that a format such as %'.2f" results in this:

php -r "printf("%'.2f", 23232323.237);"
23232323.237000

I know that number_format() will do the same, but I am given the format spec as an interface, I would need to try to parse it and then decide whether to use printf() or number_format().

0 votes
for($i=0;$i<=feof($getdata);$i++)
{
if (filter_var($data[$i][1], FILTER_VALIDATE_EMAIL)){
echo $data[$i][1];
$email=$data[$i][1];
$conn = mysqli_connect($dbhost,$dbuser,$dbpass, $dbname);
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
$sql ="INSERT INTO promo_user (uid,name,email) VALUES (,'', '$email')";
mysqli_query($sql,$conn);
mysqli_close($conn);

I am using the above code but there is something wrong with it,whenever i run the code the echo is working fine but the content does go into sql table

Please help

0 votes

PHP:: Suppose I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, whats the problem?

+1 vote

When going to the web site all see is Index of / and the page like you would see when doing a directory list, but it is blank (no files listed - just the apache version, etc.). I have looked in the logs and have checked the apache conf files and it looks the php module is set to load, but the index.php is not loading.

Any suggestions?

...