Variables in ini php files

Hi, I have this structure in my ini file. I want you to be able to 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 site.url.images.

I use zend config ini to parse my ini files. Is there a solution next to adding this feature?

+4
source share
1 answer

Zend_Config_Ini will not do this (because the built-in parse_ini_file () PHP will not do this).

So you have to get around this somehow.

Two approaches that seem obvious (to me):

  • Just don't do it. In your example, just set site.url.images for โ€œimagesโ€ and create the URLs in your application code (implement the small little function getUrlForImage ($ img), which creates the correct URL based on the configuration values โ€‹โ€‹and argument)

  • Extend Zend_Config_Ini to do some post-processing.

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

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

Then do an array of configuration values โ€‹โ€‹that perform the lookups.

+3
source

Source: https://habr.com/ru/post/1307905/


All Articles