Re: [PHP-DEV] Bug #12477 Updated: preg_replace evaluates dollar signs as variables (eg $1,000 becomes ,000)

2001-08-07 Thread Andrei Zmievski

On Mon, 06 Aug 2001, [EMAIL PROTECTED] wrote:
 ID: 12477
 User updated by: [EMAIL PROTECTED]
 Reported By: [EMAIL PROTECTED]
 Status: Closed
 Bug Type: Feature/Change Request
 Operating System: Linux and SCO
 PHP Version: 4.0.6
 New Comment:
 
 I was trying to have to walk the array twice.
 
 The following works:
 
 $pagevars = str_replace($,\\\$,$pagevars);
 $page = preg_replace($template,$pagevars,$page);
 
 The reason for using preg_replace is that it does a recursive? replace.

What do you mean, 'recursive' replace?

-Andrei
* I don't mind going nowhere as long as it's an interesting path. *

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DEV] Bug #12477 Updated: preg_replace evaluates dollar signs as variables (eg $1,000 becomes ,000)

2001-08-07 Thread Grant Walters

 On Mon, 06 Aug 2001, [EMAIL PROTECTED] wrote:
  ID: 12477
  User updated by: [EMAIL PROTECTED]
  Reported By: [EMAIL PROTECTED]
  Status: Closed
  Bug Type: Feature/Change Request
  Operating System: Linux and SCO
  PHP Version: 4.0.6
  New Comment:
 
  I was trying to have to walk the array twice.
 
  The following works:
 
  $pagevars = str_replace($,\\\$,$pagevars);
  $page = preg_replace($template,$pagevars,$page);
 
  The reason for using preg_replace is that it does a recursive? replace.

 What do you mean, 'recursive' replace?

Example (using shortened arrays):

In my system I build a complete page and then echo it to the browser.  All of the 
Navigation records and other content pages for the
site are contained in a MySql database.
The only fielsystem files that exist are the main index.php3 script, a site 
configuration file that contains defaults for variables
that is imported into a class called site, and the template pages.
The Navigation record for a page determines what needs to happen to it 
programmatically (form, database form, text, upload, download
etc...) and whether the page comes from HTTPS or HTTP servers.

//SETUP PAGE STUFF
$template=array(
  /({PAGEMAIN})/,
  /({PAGELINKS})/,
  /({PAGETEXT})/,
  /({LINKSDATA})/,
  /({PAGEDATA})/
);

$pagevars=array(
  PAGEMAIN = get_page($site-page_main),
  PAGELINKS = get_page($site-page_links),
  PAGETEXT = get_page($site-page_text),
  LINKSDATA = ,
  PAGEDATA = 
);

$page = {PAGEMAIN};

$pagevars = str_replace($,\\\$,$pagevars); // preserve dollar signs in page text
$page = preg_replace($template,$pagevars,$page);

The get_page() fuinction just grabs a text file and stuffs its contents into the 
variable.

PAGEMAIN

!-- OUTPUT MAIN BODY TABLE --
table border='0' cellpadding='0' cellspacing='0' width='{WIDTH}' height='77%'
  tr valign='top'{PAGELINKS}{PAGETEXT}/tr
/table
!-- OUTPUT MAIN BODY TABLE --

PAGELINKS
-
!-- OUTPUT LINKS SECTION CELL --
td class='background'
  table class='linkstable' width='160' border='0' cellspacing='0' cellpadding='0'
{LINKSDATA}
tr valign='top'
  td class='linksgap'img src='/{IMAGES}/clear.gif' width='158' height='3' 
border='1'/td
/tr
  /table
/td
!-- OUTPUT LINKS SECTION CELL --

PAGETEXT

!-- OUTPUT PAGE TEXT TABLE --
td width='{WIDTH}'
  table width='99%'
tr valign='top'tdimg src='/{IMAGES}/clear.gif' border='0' height='15' 
width='99%'/td/tr
tr valign='top'
  td!--PAGEDATA--
{PAGEDATA}
!--PAGEDATA--
  /td/tr
tr valign='top'tdimg src='/{IMAGES}/clear.gif' border='0' height='15' 
width='99%'/td/tr
  /table
/td
!-- OUTPUT PAGE TEXT TABLE --

Because preg_replace walks through the array from top to bottom it becomes sort of 
recursive as the resulting string keeps getting
bigger as each variable replacement occurs.

$page
- starts with {PAGEMAIN}
- replaced with PAGEMAIN template which contains {PAGELINKS}{PAGETEXT}
- {PAGELINKS} is replaced with PAGELINKS template which contains {LINKSDATA}
- {PAGETEXT} is replace with PAGETEXT template which contains {PAGEDATA}
- {LINKSDATA} is replaced with programmatically built HTML for links on page
- {PAGEDATA} is replaced with programatically built HTML for the text of the page 
(form, document etc..)

The end result is a string of HTML.

I hope this is clear.  I may have put you wrong with the use of the word recursive?  
I wasn't really sure what term to use.  Ever
Expanding?

Regards

Grant Walters
Brainbench 'Most Valuable Professional' for Unix Admin
P O Box 13-043 Johnsonville, Wellington, NEW ZEALAND
Telephone: +64 4 4765175, CellPhone 025488265, ICQ# 23511989


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] Bug #12477 Updated: preg_replace evaluates dollar signs as variables (eg $1,000 becomes ,000)

2001-08-06 Thread andrei

ID: 12477
Updated by: andrei
Reported By: [EMAIL PROTECTED]
Old Status: Open
Status: Closed
Bug Type: PCRE related
Operating System: Linux and SCO
PHP Version: 4.0.6
New Comment:

That's right, you need to escape $ in your replacement strings.

Previous Comments:


[2001-07-31 00:40:54] [EMAIL PROTECTED]

The setup for my templating system:

$template=array(
  /({PAGETOP})/,
  /({PAGENAVBAR})/,
  /({PAGEMAIN})/,
  /({PAGELINKS})/,
  /({PAGESPACE})/,
  /({PAGETEXT})/,
  /({PAGENEWS})/,
  /({PAGEBOTTOM})/,
  /({PAGEDATA})/
  );

$pagevars=array(
  PAGETOP = get_page($site-page_top),
  PAGENAVBAR = get_page($site-page_top),
  PAGEMAIN = get_page($site-page_main),
  PAGELINKS = get_page($site-page_links),,
  PAGESPACE = get_page($site-page_space),
  PAGETEXT = get_page($site-page_text),
  PAGENEWS = get_page($site-page_news),,
  PAGEBOTTOM = get_page($site-page_bottom),
  PAGEDATA = 
  );

$page = {PAGETOP}{PAGENAVBAR}{PAGEMAIN}{PAGEBOTTOM};

$page = preg_replace($template,$pagevars,$page);

echo $page;

Basically each physical page referenced via the get_page function is a text template 
that may contain HTML, text or variables in the form {VAR}.

Eventually content from a database ends up in a variable called PAGEDATA which is in 
the template stored in the page main variable.

The problem:

PAGEDATA ends up containing page text and it has something like would cost around 
$16,000 to complete in that text.

When the preg_replace is performed, something somewhere is assuming that $16 is a 
variable (which doesn't exist) and the text ends up as would cost around ,000 to 
complete








Edit this bug report at http://bugs.php.net/?id=12477edit=1


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] Bug #12477 Updated: preg_replace evaluates dollar signs as variables (eg $1,000 becomes ,000)

2001-08-06 Thread Grant . Walters

ID: 12477
User updated by: [EMAIL PROTECTED]
Reported By: [EMAIL PROTECTED]
Status: Closed
Bug Type: PCRE related
Operating System: Linux and SCO
PHP Version: 4.0.6
New Comment:

Is it possible to ask that the this be included as a new feature?

A switch to tell the PCRE engine? to ignore variable substitution?

It would make things a lot easier, I think.

Thanks

Previous Comments:


[2001-08-06 12:49:00] [EMAIL PROTECTED]

That's right, you need to escape $ in your replacement strings.



[2001-07-31 00:40:54] [EMAIL PROTECTED]

The setup for my templating system:

$template=array(
  /({PAGETOP})/,
  /({PAGENAVBAR})/,
  /({PAGEMAIN})/,
  /({PAGELINKS})/,
  /({PAGESPACE})/,
  /({PAGETEXT})/,
  /({PAGENEWS})/,
  /({PAGEBOTTOM})/,
  /({PAGEDATA})/
  );

$pagevars=array(
  PAGETOP = get_page($site-page_top),
  PAGENAVBAR = get_page($site-page_top),
  PAGEMAIN = get_page($site-page_main),
  PAGELINKS = get_page($site-page_links),,
  PAGESPACE = get_page($site-page_space),
  PAGETEXT = get_page($site-page_text),
  PAGENEWS = get_page($site-page_news),,
  PAGEBOTTOM = get_page($site-page_bottom),
  PAGEDATA = 
  );

$page = {PAGETOP}{PAGENAVBAR}{PAGEMAIN}{PAGEBOTTOM};

$page = preg_replace($template,$pagevars,$page);

echo $page;

Basically each physical page referenced via the get_page function is a text template 
that may contain HTML, text or variables in the form {VAR}.

Eventually content from a database ends up in a variable called PAGEDATA which is in 
the template stored in the page main variable.

The problem:

PAGEDATA ends up containing page text and it has something like would cost around 
$16,000 to complete in that text.

When the preg_replace is performed, something somewhere is assuming that $16 is a 
variable (which doesn't exist) and the text ends up as would cost around ,000 to 
complete








Edit this bug report at http://bugs.php.net/?id=12477edit=1


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] Bug #12477 Updated: preg_replace evaluates dollar signs as variables (eg $1,000 becomes ,000)

2001-08-06 Thread andrei

ID: 12477
Updated by: andrei
Reported By: [EMAIL PROTECTED]
Status: Closed
Bug Type: PCRE related
Operating System: Linux and SCO
PHP Version: 4.0.6
New Comment:

If you don't want to use \n or $n substitution, then maybe you are better off using 
str_replace()?

Previous Comments:


[2001-08-06 17:24:10] [EMAIL PROTECTED]

Is it possible to ask that the this be included as a new feature?

A switch to tell the PCRE engine? to ignore variable substitution?

It would make things a lot easier, I think.

Thanks



[2001-08-06 12:49:00] [EMAIL PROTECTED]

That's right, you need to escape $ in your replacement strings.



[2001-07-31 00:40:54] [EMAIL PROTECTED]

The setup for my templating system:

$template=array(
  /({PAGETOP})/,
  /({PAGENAVBAR})/,
  /({PAGEMAIN})/,
  /({PAGELINKS})/,
  /({PAGESPACE})/,
  /({PAGETEXT})/,
  /({PAGENEWS})/,
  /({PAGEBOTTOM})/,
  /({PAGEDATA})/
  );

$pagevars=array(
  PAGETOP = get_page($site-page_top),
  PAGENAVBAR = get_page($site-page_top),
  PAGEMAIN = get_page($site-page_main),
  PAGELINKS = get_page($site-page_links),,
  PAGESPACE = get_page($site-page_space),
  PAGETEXT = get_page($site-page_text),
  PAGENEWS = get_page($site-page_news),,
  PAGEBOTTOM = get_page($site-page_bottom),
  PAGEDATA = 
  );

$page = {PAGETOP}{PAGENAVBAR}{PAGEMAIN}{PAGEBOTTOM};

$page = preg_replace($template,$pagevars,$page);

echo $page;

Basically each physical page referenced via the get_page function is a text template 
that may contain HTML, text or variables in the form {VAR}.

Eventually content from a database ends up in a variable called PAGEDATA which is in 
the template stored in the page main variable.

The problem:

PAGEDATA ends up containing page text and it has something like would cost around 
$16,000 to complete in that text.

When the preg_replace is performed, something somewhere is assuming that $16 is a 
variable (which doesn't exist) and the text ends up as would cost around ,000 to 
complete








Edit this bug report at http://bugs.php.net/?id=12477edit=1


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] Bug #12477 Updated: preg_replace evaluates dollar signs as variables (eg $1,000 becomes ,000)

2001-08-06 Thread andy

ID: 12477
Updated by: andy
Reported By: [EMAIL PROTECTED]
Old Status: Closed
Status: Open
Old Bug Type: PCRE related
Bug Type: Feature/Change Request
Operating System: Linux and SCO
PHP Version: 4.0.6
New Comment:

reopened and reclassified as a feature request.

Previous Comments:


[2001-08-06 17:26:15] [EMAIL PROTECTED]

If you don't want to use \n or $n substitution, then maybe you are better off using 
str_replace()?



[2001-08-06 17:24:10] [EMAIL PROTECTED]

Is it possible to ask that the this be included as a new feature?

A switch to tell the PCRE engine? to ignore variable substitution?

It would make things a lot easier, I think.

Thanks



[2001-08-06 12:49:00] [EMAIL PROTECTED]

That's right, you need to escape $ in your replacement strings.



[2001-07-31 00:40:54] [EMAIL PROTECTED]

The setup for my templating system:

$template=array(
  /({PAGETOP})/,
  /({PAGENAVBAR})/,
  /({PAGEMAIN})/,
  /({PAGELINKS})/,
  /({PAGESPACE})/,
  /({PAGETEXT})/,
  /({PAGENEWS})/,
  /({PAGEBOTTOM})/,
  /({PAGEDATA})/
  );

$pagevars=array(
  PAGETOP = get_page($site-page_top),
  PAGENAVBAR = get_page($site-page_top),
  PAGEMAIN = get_page($site-page_main),
  PAGELINKS = get_page($site-page_links),,
  PAGESPACE = get_page($site-page_space),
  PAGETEXT = get_page($site-page_text),
  PAGENEWS = get_page($site-page_news),,
  PAGEBOTTOM = get_page($site-page_bottom),
  PAGEDATA = 
  );

$page = {PAGETOP}{PAGENAVBAR}{PAGEMAIN}{PAGEBOTTOM};

$page = preg_replace($template,$pagevars,$page);

echo $page;

Basically each physical page referenced via the get_page function is a text template 
that may contain HTML, text or variables in the form {VAR}.

Eventually content from a database ends up in a variable called PAGEDATA which is in 
the template stored in the page main variable.

The problem:

PAGEDATA ends up containing page text and it has something like would cost around 
$16,000 to complete in that text.

When the preg_replace is performed, something somewhere is assuming that $16 is a 
variable (which doesn't exist) and the text ends up as would cost around ,000 to 
complete








Edit this bug report at http://bugs.php.net/?id=12477edit=1


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] Bug #12477 Updated: preg_replace evaluates dollar signs as variables (eg $1,000 becomes ,000)

2001-08-06 Thread andrei

ID: 12477
Updated by: andrei
Reported By: [EMAIL PROTECTED]
Old Status: Open
Status: Closed
Bug Type: Feature/Change Request
Operating System: Linux and SCO
PHP Version: 4.0.6
New Comment:

To QA people (Andy): please don't be hasty.

Previous Comments:


[2001-08-06 17:26:23] [EMAIL PROTECTED]

reopened and reclassified as a feature request.



[2001-08-06 17:26:15] [EMAIL PROTECTED]

If you don't want to use \n or $n substitution, then maybe you are better off using 
str_replace()?



[2001-08-06 17:24:10] [EMAIL PROTECTED]

Is it possible to ask that the this be included as a new feature?

A switch to tell the PCRE engine? to ignore variable substitution?

It would make things a lot easier, I think.

Thanks



[2001-08-06 12:49:00] [EMAIL PROTECTED]

That's right, you need to escape $ in your replacement strings.



[2001-07-31 00:40:54] [EMAIL PROTECTED]

The setup for my templating system:

$template=array(
  /({PAGETOP})/,
  /({PAGENAVBAR})/,
  /({PAGEMAIN})/,
  /({PAGELINKS})/,
  /({PAGESPACE})/,
  /({PAGETEXT})/,
  /({PAGENEWS})/,
  /({PAGEBOTTOM})/,
  /({PAGEDATA})/
  );

$pagevars=array(
  PAGETOP = get_page($site-page_top),
  PAGENAVBAR = get_page($site-page_top),
  PAGEMAIN = get_page($site-page_main),
  PAGELINKS = get_page($site-page_links),,
  PAGESPACE = get_page($site-page_space),
  PAGETEXT = get_page($site-page_text),
  PAGENEWS = get_page($site-page_news),,
  PAGEBOTTOM = get_page($site-page_bottom),
  PAGEDATA = 
  );

$page = {PAGETOP}{PAGENAVBAR}{PAGEMAIN}{PAGEBOTTOM};

$page = preg_replace($template,$pagevars,$page);

echo $page;

Basically each physical page referenced via the get_page function is a text template 
that may contain HTML, text or variables in the form {VAR}.

Eventually content from a database ends up in a variable called PAGEDATA which is in 
the template stored in the page main variable.

The problem:

PAGEDATA ends up containing page text and it has something like would cost around 
$16,000 to complete in that text.

When the preg_replace is performed, something somewhere is assuming that $16 is a 
variable (which doesn't exist) and the text ends up as would cost around ,000 to 
complete








Edit this bug report at http://bugs.php.net/?id=12477edit=1


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] Bug #12477 Updated: preg_replace evaluates dollar signs as variables (eg $1,000 becomes ,000)

2001-08-06 Thread Grant . Walters

ID: 12477
User updated by: [EMAIL PROTECTED]
Reported By: [EMAIL PROTECTED]
Status: Closed
Bug Type: Feature/Change Request
Operating System: Linux and SCO
PHP Version: 4.0.6
New Comment:

I was trying to have to walk the array twice.

The following works:

$pagevars = str_replace($,\\\$,$pagevars);
$page = preg_replace($template,$pagevars,$page);

The reason for using preg_replace is that it does a recursive? replace.

My pagevars array actually has about 40 variables and the intention is to allow 
website designers to define their own additional variables that are added to the 
template string.

Thanks for your help.




Previous Comments:


[2001-08-06 17:29:56] [EMAIL PROTECTED]

To QA people (Andy): please don't be hasty.



[2001-08-06 17:26:23] [EMAIL PROTECTED]

reopened and reclassified as a feature request.



[2001-08-06 17:26:15] [EMAIL PROTECTED]

If you don't want to use \n or $n substitution, then maybe you are better off using 
str_replace()?



[2001-08-06 17:24:10] [EMAIL PROTECTED]

Is it possible to ask that the this be included as a new feature?

A switch to tell the PCRE engine? to ignore variable substitution?

It would make things a lot easier, I think.

Thanks



[2001-08-06 12:49:00] [EMAIL PROTECTED]

That's right, you need to escape $ in your replacement strings.



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/?id=12477


Edit this bug report at http://bugs.php.net/?id=12477edit=1


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]