Instead of this (slightly hacky but working) construct, perhaps just use spprintf? But I guess we can't use that as it's PHP specific only. There *must* be a better way for it; here and again below in the duplicated code.