div inside php not worrking - php

I am trying to style a sentence within php by trying to echo the div. However the styling is not being applied. The css is correct, I think I have something wrong on how I am calling a div withing php. Can you please advise.
This what I have tried:
echo '<div id="sumtitle">' . "<tr><td>" . "This is a test" . "</td></tr>" . '</div>';
tried also like this:
echo '<div id="test">Test sentence</div>';
thanks

PHP is not responsible for styling.
You have to check your styles file or whatever.
Check your HTML and CSS.
PHP has nothing to do here.

The code looks OK, although the multiple use of the . in the first is unnecessary. You could just put:
echo '<div id="sumtitle"><tr><td>This is a test</td></tr></div>';
BTW: Are you using a <table> for your <tr> and <td>?
Regardless, the styling should work fine if you use something like:
#sumtitle { font-style: italic; }
or
#test {...}
I'd double check the CSS! :)

Related

PHP while loop with HTML

I want to make some mini-blog using php, the code is next:
while($row = #mysql_fetch_array ($fetch)) {
echo '<div class="content-posts">';
echo $row['bio'] ;
'</div>';
}
the .content-posts Div is width:800px; and height 250px;
and I have them 5x echoed. but they go one over another (please check picture to see how it looks)
http://i.imgur.com/N5ogsMu.png
As you can see on picture, not only that divs go one over another, but also every next post goes a bit to the right, duo to border. if I delete border in CSS, they will be in same vertical line, but they will still be one over another.
can anyone suggest me proper code?
Thanks in advance!
while($row = #mysql_fetch_array ($fetch)) {
echo '<div class="content-posts">';
echo $row['bio'] ;
echo '</div>';
}
should work. Check the error-output settings of your PHP configuration. Your code above should result at least in a warning.

calling include function in echo statement

I am using whole code in php so i am using echo statement for displaying divs in html but how could i call php include function in echo statement to call a page see the code below:-
echo "<div style='position:relative;border:1px solid #A5BEBE;background-color: white;'>
include('botfunction.php');
</div>";
it is not calling that botfunction.php it just shows the text only as "include('botfunction.php');" inside the div tag .
Please tell me how can i call this php function without separating php and html code because the whole code is written in php which is impossible to separate.
Thanks
Remove the include from inside the echo.
echo "<div style='position:relative;border:1px solid #A5BEBE;background-color: white;'>";
include('botfunction.php');
echo "</div>";
which is why it's appearing as text instead of executing the include function.
This is going to be an absolute nightmare to maintain and if it is impossible to separate then I suggest rewriting from scratch. But as for your question, try this:
echo "<div style='position:relative;border:1px solid #A5BEBE;background-color: white;'>";
include('botfunction.php');
echo "</div>";
You just need to move the include out of the echo string otherwise it will be evaluated as a string instead of a function
echo "<div style='position:relative;border:1px solid #A5BEBE;background-color: white;'>";
include('botfunction.php');
echo "</div>";

php-how to echo 'get" with the formatting?

I have code like this in php
echo get($contents,'<plaintext>','</plaintext>') ;
it gives me the simple plain text.
Now i want to format this echo text with increase the font size
therefore i try
echo "<div style ='font:30px Arial,tahoma,sans-serif;color:#555'>get($contents,'<plaintext>','</plaintext>') </div>";
but it is not working how to do this??
I try this by doing more experiment but none of the things working.
plz help me on this
You need to append the function in the string. Just like this:
echo "<div style ='font:30px Arial,tahoma,sans-serif;color:#555'>" . get($contents,'<plaintext>','</plaintext>') . "</div>";

PHP - Echoing a variable in color

Im new to learning PHP as you might have guessed. I have the contents of a .txt file echoed but I would like it to stand out more, so I figured I would make it a different colour.
My code without colour:
<?php
$file = fopen("instructions.txt", "r") or exit("Unable to open file");
while(!feof($file))
{
echo fgets($file);
}
fclose($file);
?>
I have researched this and seen suggestions to others to use a div style, however this didn't work for me, it gave me red errors all the way down the page instead! I think its because I'm using 'fgets' not just a variable? Is there a way to colour the echo red?
The code I tried but doesn't work:
echo "<div style=\"color: red;\">fgets($file)</div>";
(In general) You need to separate the actual PHP code from the literal portions of your strings. One way is to use the string concatenation operator .. E.g.
echo "<div style=\"color: red;\">" . fgets($file) . "</div>";
String Operators
Other answer already told that you can't use a function call in a double quoted string. Let additionally mention that for formatting only tasks a <span> element is better suited than a <div> element.
Like this: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span
You should try:
<div style="color: red;"><?= fgets($file);?></div>
Note: <?= is an short hand method for <?php echo fgets($file);?>
This version does not need to escape double quotes:
echo '<div style="color:red;">' . fgets($file) . '</div>';
You can do this with the concatenate operator . as has already been mentioned but IMO it's cleaner to use sprintf like this:
echo sprintf("<div style='color: red;'>%s</div>", fgets($file));
This method comes into it's own if you have two sets of text that you want to insert a string in different places eg:
echo sprintf("<div style='color: red;'>%s</div><div style='color: blue;'>%s</div>", fgets($file), fgets($file2));

How to choose specific id from the array

How can I apply CSS underline to the following $name results where id=34,40 without using SQL query. Please help.
foreach($index[$parent_id] as $id) {
$name=$data[$id]["name"];
echo str_repeat('&nbsp', $level) . "$name.$id <br>";
}
Php is great at creating HTML and HTML can reference CSS without a thought.
If you have a CSS class called underline...
.underline {
text-decoration:underline;
}
...then all you need to do is wrap your output in a tag like this:
echo '<div class="underline">'.$name.$id.'</div>';
That said I'm not quite sure what you're trying to do with the str_repeat function, so you'd need to mod this to work with that.
You can apply a span around your output
echo str_repeat('&nbsp', $level) . "<span class="underline">$name.$id </span><br>";
and then style the class
.underline{text-decoration:underline;}
OR...
you can directly style it
echo str_repeat('&nbsp', $level) . "<span style=\"text-decoration:underline;\">$name.$id </span><br>";
hope this helps

Categories