【问题标题】:How can I remove the Whitespace of this PHP Code?如何删除此 PHP 代码的空白?
【发布时间】:2017-06-23 20:23:55
【问题描述】:

需要删除以下 GoogleAPI(地图)链接上的空格。 这是生成位于<head> 中的<script> 的代码。

<script async defer src="https://maps.googleapis.com/maps/api/js?v=3&key=<?JComponentHelper::getParams('com_ohanah')->get('maps_api_key_js')?>"></script>

以上代码生成的完整网址如下:

https://maps.googleapis.com/maps/api/js?v=3&key= CENSORED

这里的问题是生成的代码有一个需要删除的字符的空格。

【问题讨论】:

  • &lt;?trim(JComponentHelper.............)?&gt;
  • 回显/打印的文本是什么/在哪里?

标签: php joomla maps whitespace


【解决方案1】:

我建议在这里使用trim。如果您在左右两侧出现一些奇怪的字符,这将避免麻烦:

<script async defer src="https://maps.googleapis.com/maps/api/js?v=3&key=<?trim(JComponentHelper::getParams('com_ohanah')->get('maps_api_key_js'))?>"></script>

【讨论】:

    【解决方案2】:

    您可以将以下str_replace() 函数应用于您的网址

    $url = "https://maps.googleapis.com/maps/api/js?v=3&key= CENSORED";
    $cleanUrl = str_replace(" ", "", $url);
    

    cleanUrl 会输出

    "https://maps.googleapis.com/maps/api/js?v=3&key=CENSORED"
    

    【讨论】:

      【解决方案3】:

      最安全的方法是使用 ltrim :

      <script async defer src="https://maps.googleapis.com/maps/api/js?v=3&key=<?ltrim(JComponentHelper::getParams('com_ohanah')->get('maps_api_key_js'))?>"></script>
      

      希望对你有帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-12-19
        • 2012-08-05
        • 1970-01-01
        • 2021-09-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多