The code below is generating a result like this: http://localhost/my_website/ contact-us
$base_url="http://localhost/my_website/";
echo $link= "$base_url contact-us ";
But I am trying to get a result like this : http://localhost/my_website/contact-us
I have also tried the following code
$base_url="http://localhost/my_website/";
echo $link= "$base_url.contact-us ";
but the result is like this http://localhost/my_website/.contact-us
Could you please show me how to solve this problem?
Edit
I am very sorry, I did't clearly mention the exact problem I am facing here. I thought the above example would help my case. Actually I am trying to create a link that I will send at users email address.
My code
$base_url="http://localhost/my_website/";
$random_hash="1";
echo $link="
<a href='$base_url account/confirm_registration/$random_hash' target='_blank'>$base_url account/confirm_registration/$random_hash</a>";
But it is generating like this
http://localhost/my_website/ account/confirm_registration/1
echo $link = $base_url."contact-us";
$base_url="http://localhost/my_website/";
echo $link= $base_url."contact-us";
You just need to split it
Tested and works:
$base_url="http://localhost/my_website/";
echo $link=$base_url."contact-us";
$base_url="http://localhost/my_website/";
$link=$base_url."contact-us";
echo $link;
You need to learn about basic string concatenation: http://php.net/manual/en/language.operators.string.php
Try this:
$base_url = "http://localhost/my_website/";
$random_hash = "1";
$url_page = "account/confirm_registration/$random_hash";
$url = $base_url . $url_page;
$link = "<a href='$url'>$url</a>";
echo $link;
Related
I am trying to create the necessary url from this code however it is working and I am struggling to find out why.
$linkere = $row['message'];
echo '<a href="me.php?message=<?php echo rawurlencode($linkere); ?>">'
Currently this code is producing the url: me.php?message= . But, I would like it to create the url: me.php?message=hello for example.
Thanks for helping!
You are passing $linkere to rawurlencode(). The variable is actually named $linker.
$linker = $row['message'];
echo '<a href="me.php?message=<?php echo rawurlencode($linker); ?>">'
You have alot of syntax problems here.
first, you need to use Concatenation message='.rawurlencode($linker).'"
second your variable do not exist, it should be $linker.
Second close the tag and insert the text, in this case i used Test.
$linker = $row['message'];
echo 'Test';
Can you try this,
$linker = $row['message'];
echo 'YOUR LINK TEXT HERE';
You don't need the <? ?> and echo in your echo, it should just be:
$linkere = $row['message'];
echo 'Test';
Otherwise you are turning php on and off again to echo something within an already open instance of php in which you are already echoing.
I would like to redirect to other pages but the = sign isn't working, the page name, the title, and the id are coming from database. I tried putting . before the = but that doesn't work. I think this should be simple but couldn't figure it out. can someone help me out?
echo "".click here."";
Try like
echo "<a href='".$row['page']."=".$row['topic']."&id=".$row['id']."'>click here</a>";
Like this ?
echo 'click here';
You were just missing a few quotes and dots. This will work.
echo "<a href='".$row['page']."=".$row['topic']."&id=".$row['id']."'>click here</a>";
I'm trying to use a PHP variable to add a href value for a link in an echo statement.
Here's a simplified version of the code I want to use. I know that I can't just add the variable into the echo statement, but I can't seem to find an example anywhere that works.
$link_address = '#';
echo 'Link';
Try like
HTML in PHP :
echo "<a href='".$link_address."'>Link</a>";
Or even you can try like
echo "<a href='$link_address'>Link</a>";
Or you can use PHP in HTML like
PHP in HTML :
Link
you can either use
echo 'Link';
or
echo "Link';
if you use double quotes you can insert the variable into the string and it will be parsed.
Basically like this,
<?php
$link = ""; // Link goes here!
print "Link";
?>
as simple as that: echo 'Link';
You can use one and more echo statement inside href
Link
link : "/profile.php?usr=firstname&email=email"
This worked much better in my case.
HTML in PHP: Link
The safest way to generate links in PHP is to use the built-in function http_build_query(). This function is very easy to use and takes an array as an argument.
To create a dynamic link simply echo out the result of http_build_query() like so:
$data = [
'id' => $id,
'name' => $name
];
echo 'Link';
If you want to print in the tabular form with, then you can use this:
echo "<tr> <td><h3> ".$cat['id']."</h3></td><td><h3> ".$cat['title']."<h3></</td><td> <h3>".$cat['desc']."</h3></td><td><h3> ".$cat['process']."%"."<a href='taskUpdate.php' >Update</a>"."</h3></td></tr>" ;
I am setting up a wordpress website and want to alter a plugin to work with another so that when a news link is clicked it will open in a lightbox using an iframe. I believe the following instances to be where the link is made.
<a href="<?php echo $link; ?>
I am looking to add the following to the link, at the end.
?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]"
I am unsure of how to combine the two. I am hoping by doing so that I correctly located and understood what needed to be changed. If you want to see the full PHP file I have added it to http://pastebin.com/sFqSb1Ha
While I wouldn't mind someone telling me the answer, I would be happy to just be pointed in the right direction for the knowledge I need to study to accomplish this.
Try this:
<a href="<?php echo $link . '?iframe=true&width=100%&height=100%"' . 'rel="prettyPhoto[iframes]"'; ?>
I can see that there are a lot of $link echos in the code you provided. To apply that attrubute for all, you may set $link before, like:
$link = $link . '?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]';
(Note that " at the end is missing, because it's already provided in href="").
But if you want to use it for a single link, try
<a href="<?php echo $link; ?>?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]" ...
There is just a little problem. If in $link there are parameters in URL, it will fail, because any other param must start with &, and we have ?iframe there. So it's good to check, whetever the ? sign occurs in $link or not.
if (strpos($link, '?') > 0)
$link = $link . '&iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]';
else
$link = $link . '?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]';
Try this
<a href="<?php echo $link ."?iframe=true&width=100%&height=100%\" ". " rel=\"prettyPhoto[iframes]\" "; ?>
for echo use " you can use other varible in this
I have been using the following to add a dynamic link on a page I am writing, it works ok and appears how it should on the page but I cant help but think that I am going a bit backwards with the way its written as it looks messy. What is the correct way to write it, as if I put it all in one line it doesn't work ?..
echo '<a href="./customer-files/';
echo $customerID;
echo '/';
echo $filename->getFilename();
echo '">';
echo $filename->getFilename();
echo '</a>';
Try with
echo "{$filename->getFilename()}";
Here there is the documentation with a lot of examples of how to concatenate output.
I'd approach it like this:
$safe_customer_id = htmlspecialchars(urlencode($customerID));
$safe_filename = htmlspecialchars(urlencode($filename->getFilename()));
$safe_label = htmlspecialchars($filename->getFilename());
echo "$safe_label";
I would go with this:
$fn = $filename->getFilename();
$link = $customerID . '/' . $fn;
echo ''.$fn.'';
If you're using a template layer, it is even better to break out into PHP only when you need to:
<a href="./customer-files/<?php
echo $customerID . '/' . $filename->getFilename()
?>">
<?php echo $filename->getFilename() ?>
</a>
This way, your IDE will correctly highlight your HTML as well as your PHP. I've also ensured that all PHP is in single-line blobs, which is the best approach for templates (lengthy statements should be banished to a controller/script).
Concatenation is your friend. Use a . to combine multiple string expression into one.
echo ''.$filename->getFilename()/'';
Even better way would be
$filename = $filename -> getFilename(); //cache the filename
echo "<a href='/$customerId/$filename'>$filename</a>";
// ^ On this echo NOTICE that variables can be DIRECTLY placed inside Double qoutes.