首页 \ 问答 \ 在golang中缩小html以删除多余的空格和下一行字符(minify html in golang to delete extra spaces and next line characters)

在golang中缩小html以删除多余的空格和下一行字符(minify html in golang to delete extra spaces and next line characters)

如何创建html minifier?

package main

import (
    "fmt"
)

func HtmlMinify(html string) string {
    // todo: minify html
    return html
}

func main() {

    htmlExample := `<li>
                        <a>Hello</a>
                    </li>`
    minifiedHtml := HtmlMinify(htmlExample)
    fmt.Println(minifiedHtml) //  `<li><a>Hello</a></li>` is wanted
}

输出:

<li>
                        <a>Hello</a>
                    </li>

但我想要它

<li><a>Hello</a></li>

操场


How to create html minifier?

package main

import (
    "fmt"
)

func HtmlMinify(html string) string {
    // todo: minify html
    return html
}

func main() {

    htmlExample := `<li>
                        <a>Hello</a>
                    </li>`
    minifiedHtml := HtmlMinify(htmlExample)
    fmt.Println(minifiedHtml) //  `<li><a>Hello</a></li>` is wanted
}

outputs:

<li>
                        <a>Hello</a>
                    </li>

But I want it to be

<li><a>Hello</a></li>

playground


原文:https://stackoverflow.com/questions/27577385
更新时间:2023-07-12 06:07

最满意答案

&具有URL中的特殊含义。 $_GET['college_name']值恰好是“Agra%20Public%20Institute%20of%20Technology%20”。 &标记新参数的开始。

如果&符号被正确转义为%26那么你将有更轻松的时间。

您可以尝试插入var_dump($_GET)并查看您实际使用的数据。


The & has a special meaning in URL. the value of $_GET['college_name'] is exactly "Agra%20Public%20Institute%20of%20Technology%20". The & marks the start of a new parameter.

If the ampersand is properly escaped as %26 you will have a much easier time.

You could try inserting a var_dump($_GET) and see what the data is that you are actually working with.

相关问答

更多
  • 您可以使用preg_split与/(?<! /(?
  • 我想这就是你要找的东西 $input = "c3s34r55p21"; $array = preg_match_all('/([a-z])(\d*)/', $input, $matches); /* var_export($array); echo "\n"; var_export($matches); echo "\n"; */ $result = array_combine($matches[1], $matches[2]); var_export($result); echo "\n"; I gu ...
  • 爆炸的替代方案: $str = "#heavy / machine gun #test"; preg_match_all('/#([^\s]+)/', $str, $matches); var_dump($matches[1]); 这基本上可以找到给定字符串中的所有主题标签。 Alternative to explode: $str = "#heavy / machine gun #test"; preg_match_all('/#([^\s]+)/', $str, $matches); var_dump ...
  • 不确定数据类型是否匹配(因为我相信它全部在字符串中),但这是代码 $myarray = array(); foreach(explode("&&",$mystring) as $key=>$val) { $myarray[] = explode(";",$val); } explode命令接受一个字符串并根据某个'split key'将其转换为一个数组,在你的情况下是&& 但由于这是一个双阵列,我不得不通过一个foreach传递它,另一个爆炸解决。 Not sure if the datatyp ...
  • 1.您需要首先遍历$_POST["items"] 2.通过-展开这个数组的每个值,并将这个新来的数组赋值给你的$nalozi数组。 foreach($_POST["items"][0] as $items){ $nalozi[] = explode('-',$items); } print_r($nalozi); 输出: - https://eval.in/998660 1.You need to iterate over $_POST["items"] first 2.Explode this arr ...
  • &具有URL中的特殊含义。 $_GET['college_name']值恰好是“Agra%20Public%20Institute%20of%20Technology%20”。 &标记新参数的开始。 如果&符号被正确转义为%26那么你将有更轻松的时间。 您可以尝试插入var_dump($_GET)并查看您实际使用的数据。 The & has a special meaning in URL. the value of $_GET['college_name'] is exactly "Agra%20Publ ...
  • 我的方法更简单一些,使用preg_match_all()和简单的正则表达式代替: $string = "one and two and three and four and five"; $pattern = '/(\w+\s)+/'; preg_match_all($pattern, $string, $matches); $length = strlen($matches[0][0]); echo $matches[0][0]; // 'one and two and three and four ...
  • 试试preg_split: $str = '012A345B67Z89'; $result = preg_split("/[a-z]/i",$str); print_r($result); 这应该给你你想要的确切输出(没有逗号): Array ( [0] => 012 [1] => 345 [2] => 67 [3] => 89 ) Try preg_split: $str = '012A345B67Z89'; $result = preg_split("/[a-z]/i ...
  • 您需要使用preg_split ,它根据给定的正则表达式拆分输入。 $words = preg_split('~,(?![^()]*\))~', $str); print_r($words); DEMO 说明: ,匹配所有逗号,只有它不匹配 其次是任何字符,但不是(或) ,零次或多次 然后是一个结束括号。 如果你改变(?! to (?= ,它与匹配括号内的所有逗号相反)。 You need to use preg_split which splits the input according to the ...
  • 因为字符串包含空格以外的空格字符,所以必须使用不同的函数: preg_split('/\s+/', $row['post_content']); 这将使用pcre正则表达式为一个或多个空白字符拆分字符串。 Because the string contains whitespace characters other than spaces, you will have to use a different function: preg_split('/\s+/', $row['post_content']) ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)