I am interested to resolve next problem with php:
我有兴趣用php解决下一个问题:
I use php to fill out table in html page,using data from MySql.That is all fine,but I need to use " . " to fill spaces between name and value. I wrote a very simple sample,just to show where is problem.
我使用php来填充html页面中的表,使用来自MySql的数据。这很好,但是我需要使用“。”来填充名称和值之间的空格。我写了一个非常简单的样本,只是为了说明问题所在。
//values in database:
$name1=Weight of bag $value1=100
$name2= Bag type $value2=Oval
<table>
<tr>
<td>$name1</td>
<td>$value1</td>
</tr>
<tr>
<td>$name2</td>
<td>$value2</td>
</tr>
etc...
</table>
All is fine on result page, I get all data from database in this format:
在结果页面上一切正常,我以这种格式从数据库中获取所有数据:
Weight of bag 100
Bag type Oval
I need result to be like this:
我需要结果是这样的:
Weight of bag........100
Bag type............Oval
My problem is to fill right side of first tag with ".", and left side of second tag. I try some of basic PHP functions, but withouth result.
我的问题是用“。”和第二个标签的左侧填充第一个标签的右侧。我尝试了一些基本的PHP函数,但没有结果。
Thanx
4 个解决方案
#1
1
Try this
<?php $input = 'Weight of bag 100'; echo $output = preg_replace('/(?:\s\s+|\n|\t)/', '......', $input); ?>
Result is like this
结果是这样的
Weight of bag......100
包的重量...... 100
#2
1
Try below:
<style type="text/css">
table {
width: 200px;
}
td span {
background-color: #FFF;
}
td.name:before {
clip: rect(0px, 190px, 20px, 0px);
content: " ............................................................ ";
position: absolute;
z-index: -1;
}
td.amt {
text-align: right;
}
</style>
<table>
<tr>
<td class="name"><span>Weight of bag</span></td>
<td class="amt"><span>100</span></td>
</tr>
<tr>
<td class="name"><span>Bag type</span></td>
<td class="amt"><span>Oval</span></td>
</tr>
</table>
Demo:
#3
0
You can get rid of tables, output this in monospaced font and fill it with dots manually.
您可以摆脱表格,以等宽字体输出,并手动填充点。
Here's the function that can fill with dots: http://php.net//manual/ru/function.str-pad.php#81944
这是可填充点的功能:http://php.net//manual/ru/function.str-pad.php#81944
function pad_between_strings($string1, $string2, $length, $char = " ") {
$fill_length = $length - ( strlen($string1) + strlen($string2) );
return $string1 . str_repeat($char, $fill_length) . $string2;
}
#4
-1
<table>
<tr>
<td>$name1........</td>
<td>$value1.......</td>
</tr>
<tr>
<td>........$name2</td>
<td>........$value2</td>
</tr>
</table>
#1
1
Try this
<?php $input = 'Weight of bag 100'; echo $output = preg_replace('/(?:\s\s+|\n|\t)/', '......', $input); ?>
Result is like this
结果是这样的
Weight of bag......100
包的重量...... 100
#2
1
Try below:
<style type="text/css">
table {
width: 200px;
}
td span {
background-color: #FFF;
}
td.name:before {
clip: rect(0px, 190px, 20px, 0px);
content: " ............................................................ ";
position: absolute;
z-index: -1;
}
td.amt {
text-align: right;
}
</style>
<table>
<tr>
<td class="name"><span>Weight of bag</span></td>
<td class="amt"><span>100</span></td>
</tr>
<tr>
<td class="name"><span>Bag type</span></td>
<td class="amt"><span>Oval</span></td>
</tr>
</table>
Demo:
#3
0
You can get rid of tables, output this in monospaced font and fill it with dots manually.
您可以摆脱表格,以等宽字体输出,并手动填充点。
Here's the function that can fill with dots: http://php.net//manual/ru/function.str-pad.php#81944
这是可填充点的功能:http://php.net//manual/ru/function.str-pad.php#81944
function pad_between_strings($string1, $string2, $length, $char = " ") {
$fill_length = $length - ( strlen($string1) + strlen($string2) );
return $string1 . str_repeat($char, $fill_length) . $string2;
}
#4
-1
<table>
<tr>
<td>$name1........</td>
<td>$value1.......</td>
</tr>
<tr>
<td>........$name2</td>
<td>........$value2</td>
</tr>
</table>