Re: using placeholders and db results
| From: | Gyozo Papp | Date: | Sun, 05 Aug 2001 23:11:35 +0000 |
| Subject: | Re: using placeholders and db results | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-61367@lists.php.net to get a copy of this message | ||
Hi,
you'd better use preg_replace_callback() instead of ereg_replace in such case.
function func($arr)
{
global $row;
return $row->{$arr[1]};
} /* or something similiar, not tested btw */
$text = "Hi ##firstname## ##lastname##,";
$text = preg_replace_callback("/##(.+?)##/", 'replace_func', $text);
----- Original Message -----
From: "Matthew Delmarter" <matt@adplusonline.com>
To: "PHP Mailing List" <php-general@lists.php.net>
Sent: 2001. augusztus 6. 00:39
Subject: [PHP] using placeholders and db results
> Here is an example of my code:
>
> $text = "Hi ##firstname## ##lastname##,";
> $text = ereg_replace("##([^#]+)##", $row->."\\1", $text);
>
> $row-> is a result of using mysql_fetch_object. I would expect it to
> replace ##firstname## and ##lastname## with the value of
> $row->firstname and $row->lastname respectively... but nothing
> happens. I presume it is a variable problem...
>
> Can anyone help with this code?
>
> Matthew
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>