我需要创建一堆固定宽度格式的提要,它们在布局上都相对相同,但它们都可以有不同的格式。
例如:
Field 1 can be 30 bytes wide, left justified and padded with 0s Field 2 can be 20 bytes wide, right justified padded with spaces
我想在数据库中存储 php 的 str_pad 参数,但不知道存储 pad_type 参数的最佳方法,因为它是一个常量,我无法像这样读回它:
$field = str_pad($input, $width, $pad_string, $pad_type)
我想我可以在 $pad_type
周围包裹一个 eval()
,但这看起来很粗略。
有更好的方法吗?
我被 PHP 5.0、MySQL 4 困住了
最佳答案
使用constant()
:
$value = constant('NAME_OF_THE_CONSTANT_AS_STORED_IN_DB');
关于php - 如何在 MySQL 数据库中存储 PHP 常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7338285/