Today I Switched Friend Links to Markdown and Something Terrible Happened!

Nexmoe June 29, 2017
This article is an AI translation and may contain semantic inaccuracies.

Because the HTML code was too messy, I wanted to switch to Markdown format. I borrowed Jrotty’s code, but it didn’t do what I wanted. I tinkered for a long time and finally got it almost right, then something terrible happened…

Compressed HTML

<a class="btn btn-raised"title="分享互联网的宝藏"href="https://aoaoao.me/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgw1fbrawpcvjnj302s02sweb.jpg"> <p>树洞</p></a><a class="btn btn-raised"title="一只野生的自由Geek"href="https://blog.viosey.com/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgw1fbrb5kz8dpj304g04gglj.jpg"> <p>Viosey</p></a><a class="btn btn-raised"title="热爱技术和生活的程序员"href="http://www.yelook.com/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgw1fbrbj1a9tcj302s02sjr7.jpg"> <p>有野出没</p></a><a class="btn btn-raised"title="用code写出对二次元的热爱!"href="http://853.bronya.net/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgw1fbrbl6j81cj30hs0hs400.jpg"> <p>Sonic853</p></a><a class="btn btn-raised"title="ペロペロ"href="https://www.anotherhome.net/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgw1fbrblwpndyj309w09wt93.jpg"> <p>DIYGod</p></a><a class="btn btn-raised"title="只是一些我的胡说八道罢了"href="http://blog.jinkunchen.com/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgw1fbrbn4gkk1j30hs0hsgm9.jpg"> <p>卷卷有空格</p></a><a class="btn btn-raised"title="是萝莉控真是太好了"href="http://siitake.cn/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgw1fbrbqj62n0j3074074q3n.jpg"> <p>香菇社长</p></a><a class="btn btn-raised"title="活靠幻想,技术靠转载!"href="https://qqdie.com/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgw1fbrbrcgv0bj30b40b4408.jpg"> <p>Jrotty</p></a><a class="btn btn-raised"title=" 一只蒟蒻的日常"href="http://wnjxyk.cn/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgw1fbrbs6h3yuj30gn0gm75r.jpg"> <p>WNJXYK</p></a><a class="btn btn-raised"title="兰陵の废宅基地"href="http://blog.thkira.com/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgw1fbrbteserej30k00k0gn8.jpg"> <p>兰陵 DA☆ZE</p></a><a class="btn btn-raised"title="就好像看透了我的心思一般,你总是突然出现……"href="https://www.dreamwings.cn/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgw1fbrbukyc33j308c08c74j.jpg"> <p>千千</p></a><a class="btn btn-raised"title="一个喜欢捣鼓前端的产品汪。"href="http://shawnzeng.com/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgw1fbrbvj35yij30cj0cjmyl.jpg"> <p>Shawn</p></a><a class="btn btn-raised"title="萝莉即是一切"href="https://www.ailoli.org/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgw1fbsgaz6xf8j30go0godh5.jpg"> <p>Ailoli</p></a><a class="btn btn-raised"title="2333333333333"href="http://hi-paul.space"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgy1fc0i6dwd86j30e10e1gof.jpg"> <p>保罗</p></a><a class="btn btn-raised"title="喜欢萌妹の变态鹅"href="https://blog.conoha.vip/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgy1fc24txdskgj30g40g477s.jpg"> <p>Moehentai</p></a><a class="btn btn-raised"title="Troy的星球"href="https://itroy.cc"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgy1fc3w9wldgxj30e80e8e1c.jpg"> <p>Troy</p></a><a class="btn btn-raised"title="幻想主義者"href="https://www.54yt.net/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgy1fcccka7mfsj308m08mjrz.jpg"> <p>玉兔</p></a><a class="btn btn-raised"title="博客主要是记录日常生活,开发过程有用的东西,还有制作成果展示等等,欢迎访问。"href="https://www.fghrsh.net/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgy1fcmi1v7bpyj30go0go177.jpg"> <p>FGHRSH</p></a><a class="btn btn-raised"title="超级迷茫中。。。"href="https://hran.me/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgy1fcuxwll0lpj30b40b4q3k.jpg"> <p>Hran</p></a><a class="btn btn-raised"title="私たちはずっとμ's!!!!!!!!"href="https://kotori.love/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgy1fcvsloueiuj308c08caa7.jpg"> <p>ココロ</p></a><a class="btn btn-raised"title="我有一壶酒,足矣慰风霜。"href="https://sa.bi/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgy1fcvt6nv3cvj304q04qjra.jpg"> <p>Dragonborn</p></a><a class="btn btn-raised"title="零三青年,只会作死,喜欢喝茶、中二、敲代码❤"href="https://idiot.moe/"target="_blank"><img src="https://ws1.sinaimg.cn/large/a15b4afegy1fd3yir3bo0j20b40b43ya.jpg"> <p>蔡锶铎</p></a><a class="btn btn-raised"title="你不爱我了QAQ"href="https://www.iqi7.com/"target="_blank"><img src="https://ws1.sinaimg.cn/large/a15b4afegy1fd3ze85p3yj20hs0hsq3e.jpg"> <p>七夏浅笑</p></a><a class="btn btn-raised"title="次元隙小站"href="http://waxxh.me/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgy1fdovyvnq31j303903bq3s.jpg"> <p>Waxxh</p></a><a class="btn btn-raised"title="记录成长的点点滴滴"href="http://monsterlin.com/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgy1fdow0sn4qlj305k05ka9z.jpg"> <p>monsterlin</p></a><a class="btn btn-raised"title="泛着旧时记忆的空白扉页"href="http://www.0page.org/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgy1fdq5jy7copj3046046gmo.jpg"> <p>0page</p></a><a class="btn btn-raised"title="人生来就不是为了被打败的"href="http://ttt.lc/"target="_blank"><img src="https://ws1.sinaimg.cn/large/6513ad21jw8f5zcn0uk34j20kv0kv3zz.jpg"> <p>桃先森</p></a><a class="btn btn-raised"title="404 NOT FOUND"href="https://xiaolin.in/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgy1fec4otg2xej30dw0dwwfo.jpg"> <p>小霖</p></a><a class="btn btn-raised"title="把设计师气到脑中风2333∠( ᐛ 」∠)_"href="https://www.metheno.net/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgy1felao15513j3064064glu.jpg"> <p>metheno</p></a><a class="btn btn-raised"title="永远相信,美好的事情即将发生"href="https://blog.lim-light.com/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qly1fenes19futj30hs0hsmy7.jpg"> <p>黎明余光</p></a><a class="btn btn-raised"title="喵~"href="https://blog.taku.life/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006MhmB7gy1ff2s4jq0qsj3028028744.jpg"> <p>ギリ猫</p></a><a class="btn btn-raised"title="努力的成为一个有趣的人"href="http://neverlove.me"target="_blank"><img src="https://ws1.sinaimg.cn/large/006MhmB7gy1fh19u4rfa0j305k05k404.jpg"> <p>不才博客</p></a><a class="btn btn-raised"title="这是很好的一生"href="https://www.qqstop.cn/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006MhmB7gy1fh19v5rh1xj30b40b474i.jpg"> <p>Kevan's Blog</p></a><a class="btn btn-raised"title="暮冬时烤雪,迟夏写长信"href="https://iu.tn/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006MhmB7gy1fh19wcga7lg305k05kmyk.gif"> <p>三秋</p></a><a class="btn btn-raised"title="聆听最初的声音,向往无尽的未来"href="https://imiku.me/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006pSa7Qgy1feulw1frmsj306o06oq4i.jpg"> <p>冰凌胧月</p></a><a class="btn btn-raised"title="暮光博客是一个分享生活记录以及互联网技术文章的个人博客"href="https://muguang.me/"target="_blank"><img src="https://ws1.sinaimg.cn/large/006MhmB7gy1fh1at1iiubj3050050t8m.jpg"> <p>暮光博客</p></a>

Pretty spectacular, right?

snipaste20170629_151628.png

Yes, this was my original HTML code. Seeing this, I wasn’t happy. Manually reformatting that many entries one by one is basically asking me to do it against my conscience!

How I handled it

So I put the code above into a file called e.html, then created a zz.php (“idiot”) script.

<?php
    $str = file_get_contents("e.html");
    preg_match_all('/title="(.*?)"href="/(.</span><span style="color:#F97583">*?)"target="_blank">/is',$str,$array);
    preg_match_all('/<p>(.*?)<\/p>/is',$str,$array2);
    preg_match_all('/<img src="/(.</span><span style="color:#F97583">*?)">/is',$str,$array3);
    $x=0;
    while ($array[0][$x] != ''){
        $str = preg_replace('#title="(.*?)"href="/(.*?)"target="_blank">#','$1', $array[0][$x]);
        $str1 = preg_replace('#title="(.*?)"href="/(.*?)"target="_blank">#','$2', $array[0][$x]);
        $str2 = preg_replace('#<img src="/(.*?)">#','$1', $array3[0][$x]);
        $str3 = preg_replace('#<p>(.*?)<\/p>#','$1', $array2[0][$x]);
        echo '- !['.$str3.']('.$str2.') ['.$str3.']('.$str1.' "'.$str.'")<br>'."\n";
        $x++;
    }
?>

Result

snipaste20170629_151530.png

snipaste20170629_151356.png