Variable not detected as variable [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I wanted to ask, how I can write down a variable without it's getting detected as one.
As example:
$data = <<< DATA
<?php
$dbServername = $_POST["admin"];
?>
DATA;
$dbServername shouldn't be a variable, but $_POST["admin"]; should be one.
I want, to write with fwrite the $_POST["admin"] variable into a document. But when $dbServername also gets detected as a variable, but it should be one, it throws errors.
Any Idea how to fix this?
EDIT:
There are 2 ways:
Either escape them with a backslash \ or put the variable into curly brackets {}. That also works.

Either escape the dollar sign by adding a backslash (\) infront of the dollar sign, or use single quotes to denote the string.

Related

How to create a new product with Lazada API? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Below is the example code get from LazadaOP:
Create function in ProductsController:
Continue...
So I just try to run this but it shows the error with invalid request format.
Error Page
I just want to know what is the problem with the code, and if there some solution plz do provide some code to references.TQ
#WilliamC, you had used a single quote on your XML string, yet your double quotes inside the string are escaped (e.g. '<xml version=\"1.0\"...'). You don't have to escape double quotes inside a single quoted string.
Should have been:
'<xml version="1.0" encoding="UTF-8" ?>...'
More explanation about single vs. double quotes can be found here.

i have six array elements, what usage is better than others, and why? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
i have six variables, what usage is better than others, and why?
$a["1"];
$a1['1'];
$a2[1];
$b['b'];
$b1["b"];
$b2[b];
question is only about code optimization, can't really understand what of that is better than other
It depends how you want to use the data.
Obviously for strings, if you want it as a string, store it as so. Single vs double quotes don't matter here.
If you plan to use 1 as a number for math or comparison, do $b1[1]
$b2[b] will break actually because b is not stored as a constant as of right now and it is not a variable or numeric data. Unless you do
const b = "b" then $b2[b]
Double quotes however allow string interpolation, aka
$string = "This is a string with a variable $variable in it";
where
$string = 'A string $withabrokenvariable'; will not work

Can work out how to redirect capture page to affiliate username [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
<?php header('Location: http://potttmatrix.biz/?r=;echo $r;echo');
?>
That is what im trying at the min I want the page to redirect to the referring persons link they were first at on the referral page.
Try one of these:
header("Location: http://potttmatrix.biz/?r=$r");
or
header('Location: http://potttmatrix.biz/?r='.$r);
Your code was a bit confusing, but I am assuming that you are trying to append a variable to a string.
Edit, as suggested by Chris Hayes:
In short, single quotes will take the value of the string as a literal value, while double quotes will "parse" your variable. Therefore, with single quotes you need to append the variable from the outside of the string, where with double quotes you can just include the variable in the string and it's value will be shown instead.

Using php variable in href html links [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
here is what i am trying to do
$store='something.com';
echo '<div><h3>click on</h3><a href='.$store.'>host</a></p></div>';
what it output is
something.com
instead it should use something.com as link and output need to be host.
try for sometime to do it my own but havn't achieved any success.
This code will help you out:
<?php
$store='something.com';
echo '<div><h3>click on</h3>host</p></div>';
Note the double quotes (") between the string concatenation (') this is needed by the browser to make render the proper href element.
I am agree with the Answer of Ma'moon and it is right.
Php code does not work inside the single quotes ' ', so its required to place code inside the double quotes " ".
You can also use following method instead ↓
$store='something.com';
echo "<div><h3>click on</h3><a href='$store'>host</a></p></div>";

PHP, escape any characters [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Can I escape any character in string without using symbol "\"?
For example, programming language C# allows specify string, which does not have special characters:
#"c:\webserver\".Equals("c:\\webserver\\") // <== return true
Thanks for answers and sorry for my poor English!
to escape use addslashes(); and stripslashes() to remove added slashes
Do you want to automatically add slashes?
Then you can use built in php function:
addslashes();
http://php.net/manual/en/function.addslashes.php

Categories