[pmwiki-users] Irreproducible behavior - maybe a bug
Patrick R. Michaud
pmichaud at pobox.com
Wed May 11 00:18:43 CDT 2005
On Tue, May 10, 2005 at 11:07:55PM +0200, Joachim Durchholz wrote:
> I'm despairing over getting a markup to work. Depending on whether
> preg_replace was called before or not, Markup() will enter an endless
> recursion.
Doesn't seem like preg_replace (by itself) would be the problem --
there are quite a few times that preg_replace is called before Markup()
is called.
In your code...
> $text = '';
> $size = '';
> $attrs = '';
> $field = 'To';
> $MailForm2[$field . 'Text']
> = '<input size="$size" value="$text"$attrs>';
> $replacement =
> preg_replace(
> array('/\\$text/', '/\\$size/', '/\\$attrs/'),
> array(htmlentities($MailForm2[$field . 'Text']), $size, $attrs),
> $html
> );
> Markup(
> "mailform2-$field",
> '>links',
> '/\\(:mailform2\\s' . $field . ':\\)/i',
> $replacement);
what is a typical value for $html?
> On a tangent: if somebody knows a better way to first define a string as
> 'bla $var blub'
> and, later, have $var substituted in it, I'd be grateful. That
> preg_replace thing is rather unwieldy anyway. (I have considered eval(),
> but it seems to defeat the purpose of precompilation so I'm a bit
> cautious about it.)
Well, there's not a generic good way to do it, which is why I ended up
creating FmtPageName to do this sort of thing. But beyond that,
it's better to use str_replace over preg_replace for straight
string replacements.
I also wonder about the preg_replace you have above -- given
> $MailForm2[$field . 'Text']
> = '<input size="$size" value="$text"$attrs>';
> $replacement =
> preg_replace(
> array('/\\$text/', '/\\$size/', '/\\$attrs/'),
> array(htmlentities($MailForm2[$field . 'Text']), $size, $attrs),
> $html
> );
since '$text' is being replaced by $MailForm2[$field . 'Text'], and
that value itself contains the string '$text' in it, I wonder if there
might be some bizarre loop or occurrence there as well.
Pm
More information about the pmwiki-users
mailing list