Set line height to text inside a variable - php

I have a variable, inside there's a long sentence:
$myvar = 'i am a quite long sentence, more than 500 chars';
With css, I echo it, and I get 3 lines of text.
echo '<p>'.$myvar.'</p>';
How do I set css line height to it, cause it seems when I echo the query my line-height of 12px is ignored.
Any ideas?
Not sure I was very clear with my q.
P.S. Yes, didn't know how to explain :). Sorry... The variable gets it's value from an xml field... and, how can i explain, its echo'ed like a big chunk of teext, ignoring the styles

There are several ways to set the line-height, the easiest way is
echo '<p style="line-height:12px">'.$myVar.'</p>';
A more elegant way would be to define a class or set for all your paragraph tags a line-height.
I. css global line-height for all paragraph tags
p {line-height: 12px}
II. css file with class for line height
p.foo {line-height: 12px}
corresponding php code
echo '<p class="foo">'.$myVar.'</p>';

Related

text-orientation in class doesn't apply to tr

i need to show one row's words vertically, for that i've created a class in my stylesheet containing text-orientation:sideways then applied it on the tr , but it won't seem to work, i'm a bit new to CSS so maybe someone could help please
this it the table row
echo "<tr class='vert'>";
and this is the stylesheet
table tr.vert{
text-orientation: sideways;
}
You seem to be missing the writing-mode property..
The text-orientation CSS property sets the orientation of the text characters in a line. It only affects text in vertical mode (when writing-mode is not horizontal-tb). It is useful for controlling the display of languages that use vertical script, and also for making vertical table headers.
MDN
span {
writing-mode: vertical-rl;
text-orientation:sideways;
}
<span>Writing Mode</span>

php variable height inside div

I have the following php statement,
echo "<div style=\"background-image: url('$logo'); height: '$ratioxy';\"></div>";
I did this to make the height of the div variable depending on the background image. The code correctly inserts the $logo variable, but not the $ratioxy variable. The variable $ratioxy gives a value when I echo it, but it won't give the value inside the div. Is there any reason for this? Thanks in advance.
Try to use:
echo "<div style=\"background-image: url('{$logo}'); height: {$ratioxy}px;\"></div>";
Height should be specified with units (%, px, em, etc) because "just some digits" are not obvious for browser. Also it should be specified without quotes.

Using html with style tags in php code

I have been given the following as a template for use in an email. I am using phpmailer to mail it out, but am having a problem with the way style tags begin and end as they are conflicting with the php. If I go through thier template, I could move all the styles into a seporate style sheet or use classes and put the styles at the top of the page, but I dont want to do this unless I really have to.
Below is a generic example of what is going wrong with the code. The font names are wrapped in "s so the opening and closing tags of the style are 's , these 's are clashing with the opening and closing tags of php. I cant seem to find a way round it though as if I put,
style=""font-name","another-font"" this wont work, if I use 's at all php is then screwed up.
What is happening is in php mailer the form contents are declared as
$body = '<span style='font-size: 13.5pt;font-family:"Georgia","serif";color:white'>some content</span></html>';
You need to escape your quotes. Example:
$body = '<div style=\'background:#000;\'><p>srs business here</p></div>';
You can also work with HEREDOC (http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc). This will save you a lot of messy code.
Example:
$string = <<<SOMELABEL
Here you can put your <span style='font-family: arial, helvetica, sans-serif'>formatted code</span>
SOMELABEL;
And then:
$body = $string;
Don't do this.
Your issue is not using HTML/CSS in PHP, it's just that your strings are basically un-stringing themselves, you need to escape the quotes as #ddubs said.
However, the elaborate on the "Don't do this", you shouldn't be mixing your HTML and PHP code like this. Although it's of course not required you should be separating out your logic from presentation as much as possible.
You can simply jump out of PHP with the closing tag, and jump back in when you need it, for example (based on yours):
// code code code ...
?>
<span style="font-size: 13.5pt; font-family: 'Georgia', serif; color: white">
<?php echo $variable_from_code ?>
</span></html>
Whilst I'm on the whole crusade, you also shouldn't really be using inline styles ;-)

How to let text adapt to a set table width instead of stretching the table?

I thought that this would make a table with a set width, and that text would automatically try to fit in by starting on a new line. However, the table still gets stretched by long lines of text.
<HTML><center><table width="300" border="1"><tr><td>
<?php
If (file_exists("file.txt")){
Echo nl2br(file_get_contents("file.txt"));
}Else{
Echo "File not found.";
}
?>
</td></tr></table></center></HTML>
I think I'm forgetting something absolutely essential here.. 0.o
Change the code to this:
echo nl2br(wordwrap(file_get_contents("file.txt")));
There is a built in function in PHP called wordwrap for such tasks.
The text needs to have spaces in order for it to fit in that width. If you have one extremly long word, it will be displayed entirely on one line. You could use the php function wordwrap, which allows you to set the width of the line to a certain number of characters (http://php.net/wordwrap)
Try do it by CSS:
word-wrap:break-word
Also change your width= to style="width: 300px"

Large double quotes: best way to add them

I'm trying to wrap text in some big nice double quotes. I looked at this tutorial, but seems a little more complicated than I thought it should be. My gut tells me someone here in SO knows a smarter way. I'm open to anything: CSS, or PHP or Javascript, or Jquery (but preferably not JS/Jquery)
The tutorial doesn't look too complicated to me—I think their method is quite a good one.
If you don't like specifying one of the background images in :first-letter, you could use CSS3's support for multiple background images:
blockquote {
background: url("open-quote.gif") top left no-repeat,
url("close-quote.gif") bottom right no-repeat;
/* Other rules... */
}
...but this will only work in some browsers.
If I were you, I'd use the method described in the tutorial.
I'd recommend following the method they suggest: just add some styling on a blockquote element to give it a background image of your large quotes.
If you wanted a pure CSS solution, you can use something like this:
blockquote:before, blockquote:after {
content: '"';
font-size: 400%;
}
Of course, you'll have to play with the line heights and margins to get it looking ok, but even then, it's not gonna work in IE.

Categories