简体   繁体   English

使用空格更改字体大小和右对齐(保留空格)

[英]change font-size and right-justification with spaces (preserve spaces)

I tried to change the font-size and want to justify the text at fixed positions. 我试图改变字体大小,并希望在固定位置证明文本的合理性。

Example change the font-size 示例更改font-size

echo "<p style='text-align: left;'><span style='font-size: large; font-family: georgia,palatino; color: #003366;'> Test georgia,palatino Size: large </span></p> </br>";
$output = sprintf ('<p style="text-align: left;"><span style="font-size: large; font-family: georgia,palatino; color: black;"> Test georgia,palatino Size: large </span></p> </br>"');
echo $output;

Example with str_pad str_pad的示例

 $output = 'HTML to PHP';
 echo str_pad ( $output, 20, '*' ).'<br>';
 echo str_pad ( $output, 20, '*', STR_PAD_LEFT ).'<br>';
 echo str_pad ( $output, 20, '*', STR_PAD_BOTH ).'<br>';

Example first possibility to justify text ( works well ), at position 20 is the next text : 示例第一种证明文本合理的可能性(效果很好),位置20是下一个文本:

 echo  str_pad ( $output, 20, ' ',  STR_PAD_RIGHT ) .  str_pad ( $output, 20, ' ',  STR_PAD_RIGHT ) .'<br>' ;

Example second possibility to justify text ( works well ) 示例第二种证明文本合理性的可能性(效果很好)

 echo  sprintf("%-20s%-20s<br>" , $output, $output );

Example change the font-size of a heading ( works well ) 示例更改标题的字体大小(效果很好)

 $output = sprintf ('<div align="left" > <h2><span style="text-decoration: underline;"> Left: This will be underlined.</span></h2></div>' );
 echo $output;

Example change font-size and justify the text at fixed positions ( doesn't ok) : 示例更改font-size并在固定位置对齐文本(不正常):

$text = 'HTML to PHP'; $ text ='HTML to PHP';

// ok // 好

 echo '<pre>';
 echo  sprintf("%-20s%-20s<br>" , $text, $text );

// not ok and i haven't any idea, if it is possible to justify a text with other font-size //不行,我也不知道,是否有可能用其他字体大小来证明文本

 $output = sprintf ('<p <span style="font-size: 10pt; font-family: georgia,palatino; color: black;"> %s </span></p>', $text);

 echo str_pad ( $output, 20, '*', STR_PAD_RIGHT ) . str_pad ( $output, 20, '*', STR_PAD_RIGHT ) ;

 echo  sprintf("%-20s%-20s<br>" , $output, $output );

You just wrote span tag inside the p tag. 你刚刚在p标签内写了span标签。 You have to start the <p> . 你必须开始<p> You didn't write > and started span within <p <span that is invalid. 你没有写>并且在<p <span span内启动了无效的<p <span

I fixed it and test it again, but i can't justify the text at defined positions: 我修复它并再次测试它,但我不能证明在定义的位置的文本:

 $text = 'HTML to PHP';

 echo '<pre>';
 echo  sprintf("Test 1: %-20s%-20s<br>" , $text, $text );

 $output = sprintf ('<p> <span style="font-size: 10pt; font-family: georgia,palatino; color: black;"> %s </span></p>', $text);



// This works ok 
 echo $output;
 // This test produces a output in two lines !!!
 echo str_pad ( $output, 20, ' ', STR_PAD_RIGHT ) . str_pad ( $output, 20, ' ', STR_PAD_RIGHT ) ;
 // This test produces also a output in two lines !!!
 echo  sprintf("%-20s%-20s<br>" , $output, $output );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM