Search code examples
phpjoomlamapswhitespace

How can I remove the Whitespace of this PHP Code?


The whitespace on the following GoogleAPI (Map) link needs to be removed. This is the code that generates the <script> that is placed in the <head>.

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

The complete URL the code above generated is the following:

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

The issue here is the generated code has a whitespace of one character that needs to be removed.


Solution

  • I suggest to use trim here. This will safe the trouble if you get some strange characters on the right and the left side:

    <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>