开发者

Variables in ini files php

开发者 https://www.devze.com 2022-12-27 21:16 出处:网络
Hey I have this kinda structure in my ini file I want to be able parse a variable inside a variable value

Hey I have this kinda structure in my ini file I want to be able parse a variable inside a variable value

site.url = "www.example.com"
site.url.images = site.url "/images"

However, site.url is not parsed inside th开发者_StackOverflowe site.url.images.

I am using zend config ini to parse my ini files. Is there a solution beside adding this feature myself?


Zend_Config_Ini won't do that (since PHP's built-in parse_ini_file() won't do it).

So you'll have to work around it somehow.

The two approaches that seem obvious (to me):

  • Just don't do it. In your example, just set site.url.images to "images" and build the URLs in your application code (implement a nice little getUrlForImage($img) function that constructs the proper URL based on the config values and argument)

  • Extend Zend_Config_Ini to do some postprocessing.

In the latter case, you might be better off with something like:

site.url.image = "%%site.url%%/images"

Then walk the array of configuration values doing substitutions.

0

精彩评论

暂无评论...
验证码 换一张
取 消