How to use link (href) in specific part at php echo? [duplicate] - php

This question already has answers here:
Add PHP variable inside echo statement as href link address?
(8 answers)
Closed 3 years ago.
I want to make underline at specific part using href in php.
Please help..
Here is my code..
echo "Welcome " . $row1['name'] . "Sir ";
//I want to make underline only this part: $row1['name'];

You can actually put anchor tag directly inside your php echo
echo "Welcome <a href='#yourlink'>" . $row1['name'] . "</a> Sir ";

<?php
echo " Welcome <a href='hyperlink'>" . $row1['name'] . "</a> Sir ";
?>
This will work, without any flow

Related

Create an IF statement for a $GET request when passing variables in a URL [duplicate]

This question already has answers here:
How to verify if $_GET exists?
(7 answers)
Closed 2 years ago.
This works very well for me:
<html>
<head>
<title>Query string </title>
</head>
<body>
<?php
// The value of the variable name is found
echo "<h1>Hello " . $_GET["name"] . "</h1>";
// The value of the variable age is found
echo "<h1>You are " . $_GET["age"] . " years old </h1>";
?>
</body>
</html>
And the PHP is like this:
$_GET["name"]
$_GET["age"]
My question is, as you can see there is HTML markup in my example, just a simple H1 Tag. But - what happens if the GET parameters are not there? Then the result would be an empty H1 Tag which is not the end of the world, but I'd prefer to only show the HTML Markup IF the GET parameters are present.
Would this be possible and how would I go about it?
I guess this is the case:
if (condition)
execute statement(s) if condition is true;
else
execute statement(s) if condition is false;
So, if that's the case then IF the GET DATA is there then run the HTML?
<?php
if(isset($_GET['name'])){
echo "<h1>Hello " . $_GET["name"] . "</h1>";
}
if(isset($_GET['age'])){
echo "<h1>You are " . $_GET["age"] . " years old </h1>";
}
?>

How to change this href inside echo? [duplicate]

This question already has answers here:
How can I combine two strings together in PHP?
(19 answers)
Closed 4 years ago.
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.
<i class="fa fa-step-backward"></i> Back
this code will work. kindly use this code in your .php file.
<i class="fa fa-step-backward"></i> Back
and if you want to echo in then use this
<?php
echo "<a href=" . base_index() . "list-job-order?" . $param . " class='btn btn-success btn-flat'><i class='fa fa-step-backward'></i> Back</a>";
?>

Echo php variable inside of p tag, returns outside of the p tag [duplicate]

This question already has an answer here:
Order of output changes in php echo
(1 answer)
Closed 4 years ago.
I am using WordPress and I thought this advanced custom field would output the_field('price') inside of the p tag however it output's it before the p tag and not inside it. Thanks ahead of time.
<?php
echo "<p> Tickets Start at CA$" . the_field('price') . "</p>";
?>
This is what it looks like in html
How about:
<?php
echo "<p> Tickets Start at CA$" . get_field('price') . "</p>";
?>
The reason why you might be having issues is because the_field() prints the value using echo, so the code sample in your question ends up being equivalent to this:
<?php
echo "<p> Tickets Start at CA$" . echo get_field('price') . "</p>";
?>
Reference: https://www.advancedcustomfields.com/resources/the_field/#overview
Can you try
<p> Tickets Start at CA$ <?=the_field('price') ?></p>

How can i display form data in echo php? [duplicate]

This question already has answers here:
How to echo php code inside html which is inside php code in this situation? [duplicate]
(2 answers)
Closed 7 years ago.
How can i display form data in echo php ?
My code is:
<?php
echo "<td align='center' style='vertical-align:middle;'> Bust:
<?php
echo $_POST["bust"];
?>
<br> Waist:
<?php
echo $_POST["waist"];
?>
<br> </td>";
?>
But this doesn't work, please guide me with correct steps.
There are a lot of problems with your code.
You're using " in $_POST["bust"] but you opened echo with " as well, causing a conflict.
You're using <?php instead an echo... which is already PHP. There's no need to do this.
It is best to isolate variable printing from your code. Use string concatenation with . as such:
echo "<td align='center' style='vertical-align:middle;'> Bust: ".$_POST["bust"]."<br> Waist: ".$_POST["waist"]."<br> </td>";

Same page Hyperlink with PHP

I would like to link to another part of a php page. So $x is a value I've pulled from an array that is a hyperlink.
echo "<a href='#{$x}'>{$x}</a>" . " ";
However I am stuck in linking to the target id on the same page.
echo '<a id="$x">' . '<h2>'.strtoupper(str_replace("_", " ",($x))).' ' . 'offers'.'</h2>'.'</a>';
Sure when I hover over the link, it is passing the correct value of $x in the query string, but not linking to the because I am coding the target id part wrong.
Any help appreciated.
Volterony
If you want to visit a ID on on the page use href="#id"
echo '' . '<h2>'.strtoupper(str_replace("_", " ",($x))).' ' . 'offers'.'</h2>'.'';
Improved Code
echo '<h2>'.strtoupper(str_replace("_", " ",($x))). 'offers </h2>';

Categories