好!欢迎访问迷津渡口 现在时间是: 天气 °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
   支持一下
挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
 点赞
 签到
 表情
 图片
 代码
提交评论

清空信息
关闭评论
miembrojr
 miembrojr 2019-02-15 20:03回复
#61
<a href="http://www.teamdalarna.com/nike-air-max-new-blanco-zapatosk">nike air max new blanco</a> <a href="http://www.syairshamyoun.com/adidas-neo-canvas-white-yellow-shoesi">adidas neo canvas white yellow</a> <a href="http://www.fizalisfresh.com/adidas-neo-high-rot-gold-schuhei">adidas neo high rot gold</a> <a href="http://www.fsscas.com/hombres-nike-roshe-yeezy-boost-todas-rojo-zapatosp">hombres nike roshe yeezy boost todas rojo</a> <a href="http://www.imagimp.com/nike-flyknit-racer-lyser%C3%B8d-bl%C3%A5-skoi">nike flyknit racer lyser酶d bl氓</a> <a href="http://www.burmamaritime.com/kvinners-nike-flynit-air-max-hvit-rosa-obuvq">kvinners nike flynit air max hvit rosa</a>
miembrojr http://www.miembrojr.com/
chilangorails
 chilangorails 2019-02-15 05:00回复
#60
<a href="http://www.sugarforspice.com/air-jordan-retro-6-rosado-gamma-azul-zapatosk">air jordan retro 6 rosado gamma azul</a> <a href="http://www.mybancorphsa.com/the-north-face-mens-venture-waterproof-rain-jacket-northfaceh">the north face mens venture waterproof rain jacket</a> <a href="http://www.scopatore.com/nike-air-max-97-lila-rot-schuhej">nike air max 97 lila rot</a> <a href="http://www.galacticlogos.com/flyknit-lunar-3-gr%C3%A5-skoh">flyknit lunar 3 gr氓</a> <a href="http://www.ispardmore.com/nike-zoom-rookie-bleu-foamposite-chaussuresh">nike zoom rookie bleu foamposite</a> <a href="http://www.radioramabc.com/dope-two-tone-metal-logo-snapback-cap-hatl">dope two tone metal logo snapback cap</a>
chilangorails http://www.chilangorails.com/
mygutterdome
 mygutterdome 2019-02-15 00:03回复
#59
<a href="http://www.lakefrontlane.com/jordan-other-series-gull-r%C3%B8d-kurpesg">jordan other series gull r酶d</a> <a href="http://www.minickphoto.com/adidas-superstar-hommes-vente-schedule-obuvb">adidas superstar hommes vente schedule</a> <a href="http://www.multinutwraps.com/air-jordan-retro-4-ni%C3%B1os-verde-marr%C3%B3n-butya">air jordan retro 4 ni帽os verde marr贸n</a> <a href="http://www.paulacorley.com/nike-womens-doug-martin-olive-name-number-logo-oakland-raiders-nfl-28-long-sleeve-t-shirt-nflu">nike womens doug martin olive name number logo oakland raiders nfl 28 long sleeve t shirt</a> <a href="http://www.catcogroup.com/adidas-john-wtodas-todas-star-karaoke-kurpesb">adidas john wtodas todas star karaoke</a> <a href="http://www.charlesklamut.com/asics-gel-quantum-360-salg-australia-schuhec">asics gel quantum 360 salg australia</a>
mygutterdome http://www.mygutterdome.com/
genievres
 genievres 2019-02-11 18:18回复
#58
<a href="http://www.unefinemouche.com/north-face-apex-bionic-jacket-3xl-northfaceh">north face apex bionic jacket 3xl</a> <a href="http://www.ayuinc.com/nike-kobe-8-gold-grau-schuheq">nike kobe 8 gold grau</a> <a href="http://www.unirlisboa.com/nike-air-max-tailwind-5-femmes-vert-rose-chaussuresl">nike air max tailwind 5 femmes vert rose</a> <a href="http://www.escortfeeds.com/hombres-nike-air-max-lunar-1-negro-amarillo-zapatosq">hombres nike air max lunar 1 negro amarillo</a> <a href="http://www.rdjanitorial.com/air-jordan-retro-2-gr%C3%B8n-s%C3%B8lv-skoj">air jordan retro 2 gr酶n s酶lv</a> <a href="http://www.bookoobeats.com/mennns-nike-air-max-tn-gr%C3%B8nn-r%C3%B8d-obuvi">mennns nike air max tn gr酶nn r酶d</a>
genievres http://www.genievres.com/
themusinglens
 themusinglens 2019-02-11 03:24回复
#57
<a href="http://www.truthtapes.com/nike-zoom-pegasus-33-p%C3%BArpura-zapatosk">nike zoom pegasus 33 p煤rpura</a> <a href="http://www.veskopetrov.com/womens-nike-kd-7-grey-green-shoesi">womens nike kd 7 grey green</a> <a href="http://www.kaosmotogp.com/nike-sb-dunk-iguana-schwarz-schuhei">nike sb dunk iguana schwarz</a> <a href="http://www.doularhythms.com/mujeres-air-jordan-4-amarillo-zapatosp">mujeres air jordan 4 amarillo</a> <a href="http://www.animalpainvet.com/under-armour-curry-one-bl%C3%A5-gr%C3%A5-skoi">under armour curry one bl氓 gr氓</a> <a href="http://www.texarillo.com/nike-roshe-run-speckle-kvinners-oransje-obuvq">nike roshe run speckle kvinners oransje</a>
[url=http://www.themusinglens.com/]themusinglens[/url]
wetakids
 wetakids 2019-02-10 02:00回复
#56
<a href="http://www.knapzac.com/hommes-nike-free-run-4.0-gris-vert-obuvb">hommes nike free run 4.0 gris vert</a> <a href="http://www.nipiservices.com/new-balance-999-grau-gelb-butya">new balance 999 grau gelb</a> <a href="http://www.awningsbyben.com/corey-seager-blue-jersey-nflu">corey seager blue jersey</a> <a href="http://www.blogtourney.com/nike-air-max-90-br-gr%C3%B8n-kurpesb">nike air max 90 br gr酶n</a> <a href="http://www.buranna.com/air-jordan-retro-11-bianca-marrone-graffiti-schuhed">air jordan retro 11 bianca marrone graffiti</a> <a href="http://www.cardilwo.com/nike-air-jordan-melo-m8-nero-market-schuheg">nike air jordan melo m8 nero market</a>
wetakids http://www.wetakids.com/
ipartybooths
 ipartybooths 2019-02-09 17:25回复
#55
<a href="http://www.swnblog.com/billig-nike-hyperdunk-2015-dam%C3%A4nner-grau-skob">billig nike hyperdunk 2015 dam盲nner grau</a> <a href="http://www.weimpactmds.com/minnesota-vikings-new-era-nfl-on-field-59fifty-cap-purple-hatc">minnesota vikings new era nfl on field 59fifty cap purple</a> <a href="http://www.relsflorida.com/yeezy-boost-350-infant-pirate-black-man-runninge">yeezy boost 350 infant pirate black man</a> <a href="http://www.votuongluan.com/air-jordan-4-retro-hvid-metalleic-s%C3%B8lv-schuhea">air jordan 4 retro hvid metalleic s酶lv</a> <a href="http://www.hanayaflowers.com/nike-free-5.0-mujeres-amarillo-rosado-scarpec">nike free 5.0 mujeres amarillo rosado</a> <a href="http://www.jlchatlaw.com/nike-air-max-2019-green-uk-shoeso">nike air max 2019 green uk</a>
ipartybooths http://www.ipartybooths.com/
getwithfido
 getwithfido 2019-02-08 22:41回复
#54
<a href="http://www.shoutwithus.com/nike-air-yeezy-2-rojo-marr%C3%B3n-kurpese">nike air yeezy 2 rojo marr贸n</a> <a href="http://www.vigodog.com/jordan-retro-11-lows-infrarosso-schuhef">jordan retro 11 lows infrarosso</a> <a href="http://www.brandsdh.com/air-jordan-true-flight-gituttio-arancia-schuheb">air jordan true flight gituttio arancia</a> <a href="http://www.colorngrey.com/nike-hyperdunk-2015-low-viola-grigio-chaussuresd">nike hyperdunk 2015 low viola grigio</a> <a href="http://www.leviandval.com/nike-flyknit-racer-pitch-schwarz-friday-butyg">nike flyknit racer pitch schwarz friday</a> <a href="http://www.naomisbooks.com/netscarpe-chuteiras-nike-mercurial-superfly-scarpea">netscarpe chuteiras nike mercurial superfly</a>
getwithfido http://www.getwithfido.com/
senegalreview
 senegalreview 2019-02-08 17:05回复
#53
<a href="http://www.cremontana.com/adidas-projoator-incurza-rugby-boots-azul-schuhea">adidas projoator incurza rugby boots azul</a> <a href="http://www.holeninegolf.com/nike-huarache-amarillo-and-negro-hair-scarpeb">nike huarache amarillo and negro hair</a> <a href="http://www.boobseze.com/womens-nike-huarache-utility-black-denmark-shoeso">womens nike huarache utility black denmark</a> <a href="http://www.divyangshop.com/mennns-air-max-90-hyperfuse-r%C3%B8d-svart-kurpesb">mennns air max 90 hyperfuse r酶d svart</a> <a href="http://www.caveduperreux.com/adidas-classic-trefoil-hoodie-olive-green-zapatost">adidas classic trefoil hoodie olive green</a> <a href="http://www.fabloomsilk.com/girls-high-converse-shoesz">girls high converse</a>
senegalreview http://www.senegalreview.com/
sousoushop
 sousoushop 2019-02-07 19:09回复
#52
<a href="http://www.keleric.com/femmes-asics-gel-noosa-tri-10-noir-argent-chaussuresh">femmes asics gel noosa tri 10 noir argent</a> <a href="http://www.jeffreya.com/duke-golf-hat-hatl">duke golf hat</a> <a href="http://www.vuduchoan.com/nike-lunarglide-7-femmes-rouge-bleu-chaussuresh">nike lunarglide 7 femmes rouge bleu</a> <a href="http://www.gmfamilylaw.com/nike-free-og-negro-hombres-zapatosp">nike free og negro hombres</a> <a href="http://www.clubephytus.com/womens-nike-flyknit-roshe-run-red-blue-shoesi">womens nike flyknit roshe run red blue</a> <a href="http://www.findnewcoupon.com/dam%C3%A4nner-asics-gel-kinsei-5-himmelblau-orangen-schuhei">dam盲nner asics gel kinsei 5 himmelblau orangen</a>
sousoushop http://www.sousoushop.com/
顶部留言底部
 00:00/00:00
我想和你虚度时光 - 花房姑娘(9)
  1. 我想和你虚度时光
  2. 花房姑娘
  3. 恋恋风尘
  4. 我喜爱一切不彻底的事物
  5. 我的心里是满的
  6. Long Way
  7. 给少年的歌
  8. 晴日共剪窗
  9. 天上的月你的脸