Using php variable in href html links [closed] - php

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>";

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.

How can I add single quotes to a variable in PHP [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 5 years ago.
Improve this question
I have this:
$animal=cat;
how can I add single quotes to this variable to get an output of, for example, 'cat'?
echo "$animal";
//Output 'cat'
echo "'$animal'";
Just write signle quotes before and after variable but remember variable should be written in double quotes
simply like this
echo "'". $animal. "'";
// output 'cat'
You can do
echo "\"$animal\"";
Or you can just use single quotes instead as the following:
echo '"$animal"';
Whichever you prefer.

Some points or help needed [closed]

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 6 years ago.
Improve this question
Please tell me what's the exact function of this code
echo "<td>".$row['title']."</td>";
What does ">" sign does in that code ? I need exact and clear answer, so I appreciate help from you. Many thanks!!
It is the syntax of html. echo will print the string. when you are viewing the output in browsers, browsers need the html tags with the syntax.
Your echo statement is concatenating the strings before it prints. So '>' is the part of syntax of html tags.
example
<tag>text</tag>
the ">" is a completing the opening tag for the <a ...>. the code is really just building a string of html, and the ">" is part of the string, not a specific function.

Using ' and " in PHP String [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 8 years ago.
Improve this question
How can I use a ' and a " in a php string?
I can't use one of them because I have used both in my website code and I think it's better and easier if I make a class for the website that than just echo everything.
first of all you can escape then "this is \" and ' in a string"
or you can use HEREDOC instead
$string = <<<STR
this is a "string" with 'signs' and {$some_var} if needed
STR;
Note this rules though:
1. The choose of STR was arbitrary and you can use any phrase you would like (no spaces).
2. The row with the STR; must contain NOTHING but it (not even spaces after)

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.

Categories