好!欢迎访问迷津渡口 现在时间是: 天气 °C ~ °C

迷津渡口

越感到迷惑 越接近真理

制表符与空格互转

为了对齐,有时需要使用制表符,但是由于不同的浏览器对制表符的设置不同,导致在某些浏览器对齐不成功。

可以通过转换制表符为空格,保证按设置的转换输出。

有时又需要把多个空格合并成制表符,具体成果看代码。

注意:普通输出会把多个空格合并,只有保留格式的输出才能使用。

<?php
function pc_tab_expand($text)
{
    while (strstr($text, "\t")) {
        // 正则表达式第一个子式匹配非\t,后面匹配\t
        $text=preg_replace_callback('/^([^\t\n]*)(\t+)/m', 'pc_tab_expand_helper', $text);
    }
    return $text;
}

function pc_tab_expand_helper($matches)
{
    // 为表现结果,完整的\t转换为16个空格,可自己设置
    $tab_stop=16;
    // 实际转换的空格数和对应的表项长度有关,如此才可定长整齐排列
    return $matches[1].str_repeat(' ', strlen($matches[2]) * $tab_stop - (strlen($matches[1]) % $tab_stop));
}

function pc_tab_unexpand($text)
{
    // 参数随上面调整
    $tab_stop=16;
    $lines=explode("\n", $text);
    foreach ($lines as $i => $line) {
        // 把所有制表符扩展为空格符
        $line=pc_tab_expand($line);
        $chunks=str_split($line, $tab_stop);
        $chunkCount=count($chunks);
        // 扫描除最后一个字符段之外的所有字符段
        for ($j=0; $j<$chunkCount-1; $j++) {
            // 两个空格以上才转换,保留单个的空格
            $chunks[$j]=preg_replace('/ {2,}$/', "\t", $chunks[$j]);
        }

        // 如果最后一个字符段是相当于一个制表位的空格符
        // 将其转换为制表符;否则,不作任何处理
        if ($chunks[$chunkCount-1] == str_repeat(' ', $tab_stop)) {
            $chunks[$chunkCount-1]="\t";
        }
        // 重组所有字段
        $lines[$i]=implode('', $chunks);
    }
    //重组所有行
    return implode("\n", $lines);
}

$start='<pre>';
$stop='</pre>';
$test="11\t111\t1111\n2222\t222\t22\n33333\t333333\t3333333";
print $start.$test.$stop;
$spaced=pc_tab_expand($test);
print $start.$spaced.$stop;
$unspaced=pc_tab_unexpand($spaced);
print $start.$unspaced.$stop;


点赞0
   支持一下
挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
 点赞
 签到
 表情
 图片
 代码
提交评论

清空信息
关闭评论
jamiecirillo
 jamiecirillo 约 9 小时前回复
#158
<a href="http://www.koreazp.com/nike-air-max-1-rose-or-chaussuresk">nike air max 1 rose or</a> <a href="http://www.hiltonskyshop.com/north-face-girls-oso-hoodie-northfaceh">north face girls oso hoodie</a> <a href="http://www.lavaforchange.com/herren-nike-roshe-run-blum%C3%A4nner-gold-rosa-schuhel">herren nike roshe run blum盲nner gold rosa</a> <a href="http://www.lifeonfilms.com/adidas-neo-honeycomb-oranger-or-chaussuresq">adidas neo honeycomb oranger or</a> <a href="http://www.midlandroofer.com/nike-dunk-rojo-plata-zapatosl">nike dunk rojo plata</a> <a href="http://www.pearsonchool.com/air-jordan-retro-4-kvinders-gul-skoj">air jordan retro 4 kvinders gul</a>
jamiecirillo http://www.jamiecirillo.com/
xgaajgeg
 xgaajgeg 2019-04-19 08:56回复
#157
<a href="http://www.bowtieorg.com/nike-foamposite-rouge-and-noir-chaussuresh">nike foamposite rouge and noir</a> <a href="http://www.shaneboothmx.com/nike-lunarglide-8-gr%C3%BCn-schuheh">nike lunarglide 8 gr眉n</a> <a href="http://www.basarancarpet.com/nike-flyknit-air-max-blue-and-purple-shoesk">nike flyknit air max blue and purple</a> <a href="http://www.freedhamaal.com/converse-sort-hi-l%C3%A6der-skoj">converse sort hi l忙der</a> <a href="http://www.borbonecoffe.com/adidas-adizero-f50-dragon-fg-footballe-fluorescent-gr%C3%BCn-schwarz-schuheh">adidas adizero f50 dragon fg footballe fluorescent gr眉n schwarz</a> <a href="http://www.cammaara.com/black-converse-womens-sale-shoesk">black converse womens sale</a>
xgaajgeg http://www.xgaajgeg.com/
staholidays
 staholidays 2019-04-19 03:57回复
#156
<a href="http://www.sumumcatering.com/adidas-superstar-blanc-noir-femmes-chaussuresl">adidas superstar blanc noir femmes</a> <a href="http://www.amsinconline.com/adidas-ace-15.1-turf-argent-blanc-chaussuresl">adidas ace 15.1 turf argent blanc</a> <a href="http://www.cavestt.com/converse-alle-star-light-blau-schuhej">converse alle star light blau</a> <a href="http://www.deshiresult.com/le-coq-sportif-wei%C3%9F-leder-schuhe-schuhei">le coq sportif wei脽 leder schuhe</a> <a href="http://www.quentsons.com/converse-chuck-taylor-classic-hvit-obuvj">converse chuck taylor classic hvit</a> <a href="http://www.steugenesband.com/adidas-originals-superstar-nero-oro-scarpel">adidas originals superstar nero oro</a>
[url=http://www.staholidays.com/]staholidays[/url]
nike flyknit jaune
 nike flyknit jaune 2019-04-18 16:57回复
#155
<a href="http://www.soextfence.com/mujer-air-jordan-retro-12-blanco-rojo-zapatosi">mujer air jordan retro 12 blanco rojo</a> <a href="http://www.amemedgroup.com/adidas-galaxy-hvid-l%C3%B8b-sko-skoh">adidas galaxy hvid l酶b sko</a> <a href="http://www.shawkreizer.com/adidas-originals-zx-750-nero-scarpei">adidas originals zx 750 nero</a> <a href="http://www.powerwomanbc.com/bianca-adidas-crazylight-boost-scarpej">bianca adidas crazylight boost</a> <a href="http://www.kilaswacana.com/ladies-dak-prescott-jersey-nflh">ladies dak prescott jersey</a> <a href="http://www.hobartcomfest.com/coach-in-monogram-medium-pink-backpacks-coachh">coach in monogram medium pink backpacks</a>
nike flyknit jaune http://www.waltonranchtx.com/nike-flyknit-jaune-chaussuresl
julesmatton
 julesmatton 2019-04-18 04:14回复
#154
<a href="http://www.seocontenidos.com/frau-air-jordan-retro-6-blau-gr%C3%BCn-rosa-schuhei">frau air jordan retro 6 blau gr眉n rosa</a> <a href="http://www.elitexgaming.com/nike-mercurial-r%C3%B8d-and-bl%C3%A5-skoh">nike mercurial r酶d and bl氓</a> <a href="http://www.chezpenny.com/lyle-alzado-77-oakland-raiders-white-sewn-throwback-mens-size-jersey-nfli">lyle alzado 77 oakland raiders white sewn throwback mens size jersey</a> <a href="http://www.williherren.com/mennns-nike-internationalist-rosa-hvit-obuvk">mennns nike internationalist rosa hvit</a> <a href="http://www.alimonis.com/coach-in-signature-medium-coffee-business-bags-coachh">coach in signature medium coffee business bags</a> <a href="http://www.galvomode.com/adidas-samba-blu-suede-scarpej">adidas samba blu suede</a>
julesmatton http://www.julesmatton.com/
wapkaa
 wapkaa 2019-04-17 13:48回复
#153
<a href="http://www.hutchinsmedia.com/nike-air-max-command-leather-all-black-shoesi">nike air max command leather all black</a> <a href="http://www.datesfordate.com/nike-mujeres-air-max-2013-polarized-rosado-zapatosi">nike mujeres air max 2013 polarized rosado</a> <a href="http://www.spchemtech.com/adidas-zx-flux-r%C3%B8d-skoh">adidas zx flux r酶d</a> <a href="http://www.eadamattia.com/adidas-zx-750-maschio-grigio-nero-gituttio-scarpei">adidas zx 750 maschio grigio nero gituttio</a> <a href="http://www.citypixxel.com/maschio-nike-air-max-2016-arancia-blu-scarpej">maschio nike air max 2016 arancia blu</a> <a href="http://www.megasatinc.com/stephen-curry-jersey-youth-medium-nflh">stephen curry jersey youth medium</a>
wapkaa http://www.wapkaa.com/
litpower
 litpower 2019-04-17 05:55回复
#152
<a href="http://www.artenvironments.net/bambini-nike-light-up-scarpe-arancia-gituttio-scarped">bambini nike light up scarpe arancia gituttio</a> <a href="http://www.ascential.net/nike-air-presto-femmes-bone-schuhea">nike air presto femmes bone</a> <a href="http://www.associazioneagape.net/adidas-nitrocharge-2.0-schwarz-orange-kurpesb">adidas nitrocharge 2.0 schwarz orange</a> <a href="http://www.atientertainment.net/yeezy-350-boost-cream-bianca-tea-schuhef">yeezy 350 boost cream bianca tea</a> <a href="http://www.attawhed.net/nike-flyknit-lunar-3-himmelbl%C3%A5-hvid-butye">nike flyknit lunar 3 himmelbl氓 hvid</a> <a href="http://www.audichandler.net/kvinders-nike-air-huarache-light-gr%C3%A5-gr%C3%B8n-obuvd">kvinders nike air huarache light gr氓 gr酶n</a>
litpower http://www.litpower.net/
myrumpun
 myrumpun 2019-04-17 03:55回复
#151
<a href="http://www.postthatass.com/nike-free-5.0-mujer-negro-blanco-zapatosi">nike free 5.0 mujer negro blanco</a> <a href="http://www.houseoftys.com/le-coq-sportif-m%C3%A6nd-hvid-bl%C3%A5-r%C3%B8d-skoh">le coq sportif m忙nd hvid bl氓 r酶d</a> <a href="http://www.amvdiplomados.com/adidas-forum-mid-bianca-verde-01-scarpei">adidas forum mid bianca verde 01</a> <a href="http://www.ybsimports.com/adidas-originals-zx-flux-adv-trainers-in-grigio-scarpej">adidas originals zx flux adv trainers in grigio</a> <a href="http://www.rochlockyer.com/authentic-montreal-canadiens-jersey-nflh">authentic montreal canadiens jersey</a> <a href="http://www.allsocialdata.com/coach-handbag-madison-collection-coachh">coach handbag madison collection</a>
myrumpun http://www.myrumpun.com/
bonfanticare
 bonfanticare 2019-04-16 09:11回复
#150
<a href="http://www.theskifanatic.com/nike-lunarglide-8-himmelen-bl%C3%A5-gull-obuvl">nike lunarglide 8 himmelen bl氓 gull</a> <a href="http://www.bestoftumblr.com/air-jordan-retro-10-gr%C3%B8n-skoj">air jordan retro 10 gr酶n</a> <a href="http://www.thehogrider.com/a-buon-mercato-arancia-nike-shox-scarpel">a buon mercato arancia nike shox</a> <a href="http://www.artpreneure.com/womens-air-jordan-retro-8-red-blue-shoesj">womens air jordan retro 8 red blue</a> <a href="http://www.thefarmergirl.com/air-jordan-melo-sort-mintgr%C3%B8n-skok">air jordan melo sort mintgr酶n</a> <a href="http://www.shetablink.com/mennns-asics-gel-sendai-2-rosa-gull-obuvp">mennns asics gel sendai 2 rosa gull</a>
bonfanticare http://www.bonfanticare.com/
sophiecrooks
 sophiecrooks 2019-04-15 19:13回复
#149
<a href="http://www.ptsbarwinslow.com/nike-air-max-2015-hvit-gr%C3%A5-obuvi">nike air max 2015 hvit gr氓</a> <a href="http://www.sarhallafk.com/nike-hyperrev-azul-zapatosl">nike hyperrev azul</a> <a href="http://www.philippikus.com/oakleys-deviation-blue-frame-purple-lens-sunglassesh">oakleys deviation blue frame purple lens</a> <a href="http://www.pngoilgas.com/bon%C2%A8%C2%A6-new-era-9fifty-snapback-new-york-yankees-hatj">bon篓娄 new era 9fifty snapback new york yankees</a> <a href="http://www.goficarwash.com/nike-lunarglide-6-maschio-blu-scarpej">nike lunarglide 6 maschio blu</a> <a href="http://www.getairtijuana.com/adidas-protator-lethal-zones-sl-schuhei">adidas protator lethal zones sl</a>
sophiecrooks http://www.sophiecrooks.com/
顶部留言底部
 00:00/00:00
我想和你虚度时光 - 花房姑娘(9)
  1. 我想和你虚度时光
  2. 花房姑娘
  3. 恋恋风尘
  4. 我喜爱一切不彻底的事物
  5. 我的心里是满的
  6. Long Way
  7. 给少年的歌
  8. 晴日共剪窗
  9. 天上的月你的脸