0
0

More than 3 years have passed since last update.

smartyの定数の文頭にスペースが入るときの対処方法【PHP】

Posted at

結論

stripで空白を削除する
{$smarty.const.HOGE|strip:null}

状況

動作環境
PHP 7.3.11
Smarty 3.1.34

smartyでPHPの定数を呼び出して直接利用したいときに、なぜか文頭に1スペースが入ってしまっていた。

<?php
define("HOGE", "https://fuga.co.jp");
<div><a href="https://sample.co.jp/?nexturl={$smarty.const.HOGE}">リンク先</a></div>
〇のようになってほしかったが、なぜか×のように1スペース入る
〇 https://sample.co.jp/?nexturl=https://fuga.co.jp
×  https://sample.co.jp/?nexturl= https://fuga.co.jp

結局理由はよくわからなかったが、smartyに用意されているstripを利用することで、無事に解決しました。
なぜスペースが入り込んでしまうのか分かる方はぜひ教えてください。

stripで空白を削除する
<div><a href="https://sample.co.jp/?nexturl={$smarty.const.HOGE|strip:null}">リンク先</a></div>

 https://sample.co.jp/?nexturl=https://fuga.co.jp
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0