PHP use a variable in a string [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I hava a problem at my PHP script!
I want to do something like
echo "hello $var";
And the output should be "hello $var". So it should not take the value of $var, but a string "$var".
I want to use this to create a php file with a php script...
Is there any way to solve this?
Thanks in advance!

Use single quotes:
echo 'hello $var';
Or escape the $:
echo "hello \$var";

Related

Adding a pass with # and \ characters to define('FTP_PASS' '#Aj\Zx5YJG') [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
i want to add a password to this line :
define('FTP_PASS' '#Aj\Zx5YJG')
but wp-confing will not recognize # and \ as characters and for that reason my website goes down.
How can i add those characters as text there?
thanks!
Typo? you're missing a comma between the two parameters and the quotes on the screenshot do not look regular.
http://php.net/manual/en/function.define.php
define('FTP_PASS','#Aj\Zx5YJG');
define('FTP_PASS' '\#Aj\\Zx5YJG')
Escape the characters or use different brackets

Include path with constant and variable [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I'm trying to include a file to current php page but the name of the file depens on the lang.
This line does not work:
include_once PATH.'lang/'.$_SESSION['lang'].'.php';
How can I achieve that?
Your problem should be the "PATH". It must be a string to concatenate with the other strings. For example:
include_once '/sites/all/files/'.'lang/'.$_SESSION['lang'].'.php';
Also be careful with the slashes that make your path to the file.

Image retrieval from mysql database in php not working [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I am getting an image from mysql database and trying to show it. I am using the following code. But its not working .What's the mistake i am making?
while ($row=mysql_fetch_array($result,MYSQL_ASSOC)) {
$photo=$row['photo'];
$name=$row['firstname'].' '.$row['lastname'];
$email=$row['email'];
echo "<tr><td>".'<img src="data:image/jpeg;base64,<?php echo base64_encode( $photo ); ?>" />'.'</td><td>'.$name.'</td><td>'.$email.'</td></tr>';
}
Strip the double quotes after img src because you have already used a single quote before and it is being taken a string so remove double quotes
Ok thanks. I could solve the problem. I just changed the echo line as following
echo "<tr><td>".'<img src="data:image/jpeg;base64,'.base64_encode($photo).'" alt="photo">'."</td><td>".$name."</td><td>".$email."</td></tr>";

Php help find where is syntax error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
foreach($db->fetch_array("SELECT id_categories FROM csn_categories_join_kartes where id_kartes===".$card['id']."") as $kat){
echo (kat['id_categories']);
}
table cols and values are all matched, something is wrong in this part of code
I tried adding $ before kat and using only one "=", sill doesnt work
NEW LINK
http://pastebin.com/RPK7vEaJ
this
where id_kartes===".$card['id']."
would be
where id_kartes=".$card['id']."
and missing $
echo $kat['id_categories'];
so full code :-
foreach($db->fetch_array("SELECT id_categories FROM csn_categories_join_kartes where id_kartes='".$card['id']."'") as $kat){
echo $kat['id_categories'];
}
best practice if you store your query result in a variable and loop over this variable.
foreach($db->fetch_array("SELECT id_categories FROM csn_categories_join_kartes where id_kartes=".$card['id']."") as $kat)

Confused about PHP syntax error [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I am following video tutorials on the Internet, and this is one of them. However, I am getting a syntax error and can't find where it is.
<?php
function hesapla($ilktarih,$sontarih){
$yil=$son-$ilk;
$ay=$yil*12;
$gun=$ay*30;
return array("$ilktarih","$sontarih","$yil","$ay","$gun");
}
$ilktarih=$_POST["ilk"];
$sontarih=$_POST["ikinci"];
hesapla($ilktarih,$sontarih);
list ("$ilktarih","$sontarih",$yil,$ay,$gun)=hesapla($ilktarih,$sontarih);
?>
Remove double quotes from list variables like this :
<?php
function hesapla($ilktarih,$sontarih){
$yil=$son-$ilk;
$ay=$yil*12;
$gun=$ay*30;
return array("$ilktarih","$sontarih","$yil","$ay","$gun");
}
$ilktarih=$_POST["ilk"];
$sontarih=$_POST["ikinci"];
hesapla($ilktarih,$sontarih);
list ($ilktarih,$sontarih,$yil,$ay,$gun)=hesapla($ilktarih,$sontarih);
?>

Categories