How can I make a $function echo <div> PHP [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
Hey I have a question that I can not seem to figure out, how can I make a $function echo a html markup like this code:
<div style="color: purple;">Hello</div>
I can not seem to get it. Here is the code I am using is not working:
$contactUs = echo <div style="color: green;">click here</div>;
How can I make my $function work?

$contactUs = '<div style="color: green;">click here</div>';
echo $contactUs;

Not really sure what you're asking about, but you can do:
$function = function() { echo '<div style="color: green;">click here</div>'; };
...
$function();

1° In php, all strings need to be surrounded by quotes:
'<div style="color: green;">click here</div>';
Then, echo is a language construct which send text to output (your screen for example);
// If you want to use a variable
$contactUs = '<div style="color: green;">click here</div>';
echo $contactUs;
// but you can use echo 'your string':
echo '<div style="color: green;">click here</div>';

Related

PHP - Changing HTML text with variable from MYSQL database [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm working on a website and I've got up to a bit now where I want text on the homepage to change, depending on whether or not the user is logged in. Before doing this, I wrapped the text in a div class, which has allowed me to configure how it looks inside a css file. By default, if the user is not logged in, the index.html should display "iBPBuyer, Amazing Deals & Prices." and when the user is logged in, it should then change that text to a simple welcome message, stating their name afterwards, but I cannot seem to get it working.
<?php
require("includes/application_top.php");
require("includes/site_header.php");
require("includes/application_bottom.php");
if($_SESSION['id']) {
echo '<div class="hero-text-box">
<h1>Welcome,<br> $_SESSION['first'].</h1>
</div>
<div class="row">
</div>';
} else {
echo '<div class="hero-text-box">
<h1>iBPBuyer,<br> Amazing Deals & Prices.</h1>
</div>
<div class="row">
</div>';
}
?>
Logged part should be:
echo '<div class="hero-text-box">
<h1>Welcome,<br>' . $_SESSION['first'] . '</h1>
</div>
<div class="row">
</div>';
So, it's just correct concatenation technique.
Simplify your code
$welcome = "iBPBuyer,<br> Amazing Deals & Prices.";
if($_SESSION['id']) {
$welcome = 'Welcome,<br> ' . $_SESSION['first'];
}
echo '<div class="hero-text-box">
<h1>' . $welcome . '</h1>
</div>
<div class="row">
</div>';

How to change this to HTML from 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 8 years ago.
Improve this question
i want to change this into html format
echo " http://somedomain/somepath/usn_handler.php?usn='" . $row['usn'] .
"' >" . $row['usn'] . " ";
This will work
?>
link
<?php
If you are just making a link to the same domain omit the full URL
?>
link
<?php
Assuming you want to make a hyper link. But really you should just google first.
I think you mean something like this :
<div>
http://somedomain/somepath/usn_handler.php?usn=<?php echo $row['usn']; ?>' >" <?php echo $row['usn']; ?>
</div>
or :
<div>
<a src="http://somedomain/somepath/usn_handler.php?usn=<?php echo $row['usn']; ?>" > <?php echo $row['usn']; ?></a>
</div>

pull Else if from SQL [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
I need the data to have a different style if the sold = 0 in the mysql table
and when i use the code below the website shows a blank white page
(?=$vehicle-> this is the vehicle reference
and sold is the column withing the sql table
<?php
if (?=$vehicle->sold?!= 1)
{
<div class="foo">
<div class="fboverlay"></div>
<a>
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
</a>
</div>
}
else {
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
}
?>
You need to learn the PHP from the basics. Learn about operators, PHP and HTML secion, etc..
Anyway, i fixed your code. The condition is if $vehicle->sold is not equal to 1. But i think, (in your OP you mentioned it should be 0) you want this: $vehicle->sold == 0
//Use sytnax like this. See php opeartors.
if ($vehicle->sold != 1) {
?> <!-- Close the php -->
<div class = "foo">
<div class = "fboverlay"></div>
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
</div>
<?php
//Open the php again
} else {
?> <!-- close the php -->
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
<?php //Open again
}

Selecting php out with JQuery [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
This is a code snippet I have and I would like to be able to select the out of PHP. When I try to grab the PHP output and store it into a variable, I receive "undefined".
<h1 id=<?php echo '$test; ?> class="list-name--original">
My last attempt I tried this code:$("h1.list-name--original")[0].outerHTML);
Why not just put all your PHP output in a variable
<script>
var data = '<?=$test?>';
</script>
You can then set the contents of an H1 tag like this
<h1 id="myid"></h1>
<script>
$('h1#myid').text(data);
</script>
Try
<h1 id="<?php echo $test; ?>" class="list-name--original">
in jQuery
$(".list-name--original").html();
or
$("#<?= $test ?>").html();
Try this:
<?php $test = "Hello world!"; ?>
<h1 id="example" class="list-name--original"><?php echo $test; ?></h1>
<script language="javascript">
$("#example").html();
</script>

How can I bold HTML text in an array using 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 8 years ago.
Improve this question
I have this small piece of code
<?php
foreach ($options['attributes_info'] as $attribute) :
?>
<?php
echo '<br/> ' .
$this->getPdfHelper()->fixEncoding(
$attribute['label'] . ': ' . $attribute['value']
)
?>
<?php
endforeach;
?>
How can I bold (HTML tag <b>) the 'value' that is echoed?
<?php foreach ($options['attributes_info'] as $attribute) : ?>
<?= $this->getPdfHelper()->fixEncoding($attribute['label']) ?> : <b><?= $this->getPdfHelper($attribute['value']) ?></b>
<?php endforeach; ?>
You can wrap the text with the tag.
<p><b>This text is bold</b>.</p>
http://www.w3schools.com/html/html_formatting.asp
You can simply surround it with the tag:
'<b>' . $attribute['value'] . '</b>'

Categories