How can I style a PHP echo text?
You can style it by the following way:
echo "<p style='color:red;'>" . $ip['cityName'] . "</p>";
echo "<p style='color:red;'>" . $ip['countryName'] . "</p>";
How do I style my text inside an echo?
Addition to Sidsec9's answer: if you are afraid of stylesheets, you can also consider:
echo '<p style="color: red; font-size: 10pt;">' . $row['firstname'] . " " . $row['lastname'] . '</p>';
You could also use styles to get rid of
, for example using margin-right
or padding-right
properties.
Can't style PHP echo
You're not echoing anything in the div.php block. $output
is never defined in your code. You echo plenty of times before the div.php block.
It seems to me you want to define, or append, $output
instead of echo in the various sections like:
echo "No results";
Or just put the <div class="php">
before the PHP block so the echoes will be inside of it.
CSS Styling in PHP echo
Just make sure the css file is linked in that php file. you can declare html doc under and link the css their
how to style php echo output
try
echo "<div id=\"errormsg\"> Error </div>";
Style PHP echo output(s) differently
You should make use of two individual elements (such as <span>
) and give them unique classes or IDS which you can then style. In the following, .posts
contains the string Posts
and will be red, while .num-posts
contains $user['num_posts']
and will be yellow.
<a href="" class="commposts">
<?php echo "<span class='posts'>Posts</span>" . "<span class='num-posts'>" . $user['num_posts'] . "</span>"; ?>
</a>
.posts {
color: red;
}
.num-posts {
color: yellow;
}
How to assign a css class to echo $output
Try writing a page that ONLY has this code:
<style>
.errormsg {
color: red;
}
</style>
<?php $output='hello'; echo '<p class="errormsg">' . $output . '</p>'; ?>
That will work. You must have something else interfering with your style declaration, or maybe $output has some html that overrides the red color. What I'm offering you is more troubleshooting advice than anything, because your code should work - provided your css is inside a <style>
tag.
Then, you're just going to have to step-by-step work the working code into your page till you figure out what breaks it. Troubleshooting...
How do I style my text inside an echo?
Addition to Sidsec9's answer: if you are afraid of stylesheets, you can also consider:
echo '<p style="color: red; font-size: 10pt;">' . $row['firstname'] . " " . $row['lastname'] . '</p>';
You could also use styles to get rid of
, for example using margin-right
or padding-right
properties.
Related Topics
Insert Data Through Ajax into MySQL Database
C#'s Null Coalescing Operator () in PHP
How to Keep JSON_Encode() from Dropping Strings with Invalid Characters
How to Get the Newest File in a Directory in PHP
Which Line Break in PHP Mail Header, \R\N or \N
Should I Use Prepared Statements for MySQL in PHP Performance-Wise
Preg Match Text in PHP Between HTML Tags
MySQL Error "Too Many Connections"
Debug a Domdocument Object in PHP
Simple HTML Dom File_Get_HTML Not Working - Is There Any Workaround
How to Count the Numbers of Rows That a MySQL Query Returned
What Does This Mean in PHP: -> or =>