I have written a PHP script that goes through and changes the HTML generated by Visual Page. (I know - it is a REALLY old program - but I like it.) Anyway, in each of these HTML web pages I'm working with I put in:
{copyright}
Where I want the copyright to show up. I did the following loop:
foreach( $file as $k1=>$v1 ){
if( preg_match("/\{copyright\}/i", $v1) ){
$file[$k1] = preg_replace( "/\{copyright\}/i", $copyright, $v1 );
}
}
This DID NOT WORK. I would echo out the $file[$k1] before and after the IF statement so I could see what was going on and PHP just wouldn't change the {copyright} to the copyright. The variable $copyright had something similar to:
<tr><td>Copyright 2007-NOW MyCompany. All rights reserved.</td></tr>
Now - here is the freaky thing: I put a BREAK after it did the preg_replace - and - it worked. So just changing the above to
foreach( $file as $k1=>$v1 ){
if( preg_match("/\{copyright\}/i", $v1) ){
$file[$k1] = preg_replace( "/\{copyright\}/i", $copyright, $v1 );
break;
}
}
Made it work. Does anyone have ANY kind of an idea why? I'm completely stumped by this.
Note: I thought I'd post what I had gotten the HTML down to.
<html>
<head>
<title>Test</title>
</head>
<body>
<table border='1' cellspacing='0' cellpadding='0'><tbody>
<tr><td>This is a test</td></tr>
{copyright}
</tbody></table>
</body>
</html>
That is what I boiled my test case down to.
Also note : I did get this to work. Don't know why I had to put in a BREAK statement and I put it in on a whim. My thinking went "Maybe there is something that is making it re-evaluate the string after the change? Let me try putting in a break statement." I did and - it worked. But I have no idea WHY it worked.