add html as option to a variable [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 8 years ago.
Improve this question
I have this code :
$variable_name = bla bla bla;
I want to add to this variable this code :
<a class="screenshot" rel="<?php echo $baseurl.$this->row->image; ?>" >
<div class="photo"></div>
</a>
Can somebody PLEASE help?
Thank you

You assign it to your variable like any other string. However, since you are already in php mode, you have to remove <?php ?>, and use string contatenation operator . to include $baseurl.$this->row->image
$variable_name = '<a class="screenshot" rel="' . $baseurl.$this->row->image . '" >
<div class="photo"></div>
</a>';

Related

How to write PHP if statement inside PHP string element? [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 1 year ago.
Improve this question
$element = " <div class='product-info'>
<p>$Name</p>
<?php if () {}?>
<p>$Title</p>
</div>";
this variable $element contains HTML code and I want to run this if statement inside of it but without splitting the variable because I want to echo this whole variable somewhere else.
You can't do what you're asking, but you can do something that has the same effect:
$element = " <div class='product-info'><p>$Name</p>";
if (some condition) {
$element .= "some text";
} Else {
$element .= "Some other text";
}
$element .= "<p>$Title</p> </div>";

Convert plain text URLs to HTML hyperlink in PHP [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 3 years ago.
Improve this question
I have a form in HTML, i ask the user to enter a url, once that happens it comes back in plain text in PHP. What i want to happen is that when they enter their URL and submit the link that they have entered will become clickable. This is the code i have. I hope this helps.
<?php
$firstname = $_POST['firstname'];
$course = $_POST['course'];
$projecturl = $_POST['projecturl'];
echo "<p>You are <span class='textblue'> $firstname</span> and ";
echo "your course at the college is: <span class='textblue'> $course </span></p> ";
echo "your project url is: <span class='textblue'> $projecturl</span></p> ";
echo "a href=’google.com’>Google</a>” .
?>
Try to use parse_url, for example:
<?php
$url = '//www.example.com/path?googleguy=googley';
var_dump(parse_url($url));
?>
If you want to search more about this code:
https://www.php.net/manual/en/function.parse-url.php
change echo statements like this
echo "<p>You are <span class='textblue'>.'"$firstname"'.</span> and ";

How to do inline styling in html/php? [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 4 years ago.
Improve this question
I am working on a website in which I want to do inline styling inside php tags.
<?php
if($data['item']->hello_world!=null)
{
echo "policy:";
echo strtolower($data['item']->hello_world->name);
echo "<br>";
echo strtolower($data['item']->hello_world->description);
}
?><?php
if($data['item']->hello_world!=null)
{
echo "policy:";
echo strtolower($data['item']->hello_world->name);
echo "<br>";
echo "<br>";
echo strtolower($data['item']->hello_world->description);
}
?>
The data which I want to style coming from the php code is:
echo strtolower($data['item']->hello_world->name);
Problem Statement:
I am wondering what changes I should make in the php code so that I am able to do styling for the above mentioned line.
To inline style the element:
echo '<span style="color: red">' . strtolower($data['item']->hello_world->name) . '</span>';

Trying to make this entire line of code into a hyperlink [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
echo <a href = 'test.php'> "CategoryID: " . $row["CategoryID"]. " - Category Name: ".$row["CategoryName"]. </a> "<br>";
This is what i have an is not working properly.
This:
echo "<a href = 'test.php'>CategoryID: {$row['CategoryID']} - Category Name: {$row['CategoryName']}</a><br />";
I am using the { and } as they allow you to include an array in a string and ignore the concatenation which I find harder to read.
I find it funny that you can loop through a MySQL array but can't echo a simple string :P
Some links (teach a man to fish...):
W3Schools
PHP documentation
Codecademy
Tutorials Point
Try this:
<?php
$link = "";
$link = sprintf("<a href = 'test.php'>CategoryID: %d - Category Name: %s </a><br />", $row['CategoryID'], $row['CategoryName']);
echo $link;
?>
Assuming that $row['CategoryID'] is an integer and $row['CategoryName'] is a string.

I need to display html using json encode [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
I have a form and am using json encode. It displays like the below.
[{"approveNight":"A","approve":"A","Comments":"bbb","Email":"email#email.com"}]
I am using this, but I would like it to display html. What am I missing?
<?php
$data = array($jsonData);
echo json_encode($data);
?>
I would like it to display as
Approve: yes or no
Approve: yes or no
comments: the comments
email: email address that they typed in
Try this and see if this helps:
$arrValues= json_decode($data);
print 'Approve: '.($arrValues['approve']=='A' ? 'Yes' : 'No').'<br />'
. 'Comments: '.$arrValues['Comments'].'<br />'
. 'Email: '.$arrValues['Email'].'<br />'
. 'Approve Night: '.($arrValues['approveNight']=='A' ? 'Yes' : 'No');

Categories