Using preg_replace to modularize code
Posted: Sat Jul 09, 2005 1:43 pm
I'm trying to clean up my code a bit more by taking almost all of the HTML out of it. I'm using a separate file that stores the HTML I need, and using preg_replace to fill in the data.
It's almost working except for one thing
my html is simple, it looks like this:
the PHP is straightforward too:
the problem is the result is this
#1#
#2#
meaning it is replacing "CATEGORY" but not the hash's (#)
I'm new to regex's so I'm pretty sure I'm doing something wrongCATEGORY#</td>
</tr>
the PHP is straightforward too:
the problem is the result is this
#1#
#2#
meaning it is replacing "CATEGORY" but not the hash's (#)
I'm new to regex's so I'm pretty sure I'm doing something wrongfill in the data.
It's almost working except for one thing
my html is simple, it looks like this:
the PHP is straightforward too:
the problem is the result is this
#1#
#2#
meaning it is replacing "CATEGORY" but not the hash's (#)
I'm new to regex's so I'm pretamp;quote;5">#CATEGORY#</td>
</tr>
the PHP is straightforward too:
the PHP is straightforward too:
the problem is the result is this
#1#
#2#
meaning it is rep I'm using a separate file that stores the HTML I need, and using preg_replace to fill in the data.
It's almost working except for one thing
my html is simple, it looks like this:
the PHP is straightforward too:
the PHP is straightforward too:
the problem is the result is this
#1#
#2#
meaning it is replacing "CATEGORY" but not the hash's (#)
I'm new to regex's so I'm pretty sure I'm doing something wrongand using preg_replace to fill in the data.
It's almost working except for one thing
my html is simple, it looks like this:
the PHP is straightforward too:
the PHP is straightforward too:
the PHP is straightforward too:
the problem is the result is this
#1#
#2#
meaning it is replacing "CATEGORY" but not the hash's (#)
I'm new to regex's so I'm pretty sure I'm doing something wrong
It's almost working except for one thing
my html is simple, it looks like this:
Code: Select all
<tr>
<td colspan="5">#CATEGORY#</td>
</tr>Code: Select all
//The HTML file
$header_array = file("header.html");
$header = implode("", $header_array);
//Information from the database
$category = $row['category'];
//preg_replace function
print preg_replace("#CATEGORY#", $category, $header);#1#
#2#
meaning it is replacing "CATEGORY" but not the hash's (#)
I'm new to regex's so I'm pretty sure I'm doing something wrongCATEGORY#</td>
</tr>
the PHP is straightforward too:
Code: Select all
//The HTML file
$header_array = file("header.html");
$header = implode("", $header_array);
//Information from the database
$category = $row['category'];
//preg_replace function
print preg_replace("#CATEGORY#", $category, $header);#1#
#2#
meaning it is replacing "CATEGORY" but not the hash's (#)
I'm new to regex's so I'm pretty sure I'm doing something wrongfill in the data.
It's almost working except for one thing
my html is simple, it looks like this:
Code: Select all
<tr>
<td colspan="5">#CATEGORY#</td>
</tr>Code: Select all
//The HTML file
$header_array = file("header.html");
$header = implode("", $header_array);
//Information from the database
$category = $row['category'];
//preg_replace function
print preg_replace("#CATEGORY#", $category, $header);#1#
#2#
meaning it is replacing "CATEGORY" but not the hash's (#)
I'm new to regex's so I'm pretamp;quote;5">#CATEGORY#</td>
</tr>
the PHP is straightforward too:
Code: Select all
//The HTML file
$header_array = file("header.html");
$header = implode("", $header_array);
//Information from the database
$category = $row['category'];
//preg_replace function
print preg_replace("Code: Select all
//The HTML file
$header_array = file("header.html");
$header = implode("", $header_array);
//Information from the database
$category = $row['category'];
//preg_replace function
print preg_replace("#CATEGORY#", $category, $header);#1#
#2#
meaning it is rep I'm using a separate file that stores the HTML I need, and using preg_replace to fill in the data.
It's almost working except for one thing
my html is simple, it looks like this:
Code: Select all
<tr>
<td colspan="e;5"e;>#CATEGORY#</td>
</tr>Code: Select all
//The HTML file
$header_array = file("e;header.html"e;);
$header = implode("e;"e;, $header_array);
//Information from the database
$category = $rowї'can up my code a bit more by taking almost all of the HTML out of it. I'm using a separate file that stores the HTML I need, and using preg_replace to fill in the data.
It's almost working except for one thing
my html is simple, it looks like this:Code: Select all
<tr>
<td colspan="5">#CATEGORY#</td>
</tr>Code: Select all
//The HTML file
$header_array = file("header.html");
$header = implode("", $header_array);
//Information from the database
$category = $row['category'];
//preg_replace function
print preg_replace("#CATEGORY#", $category, $header);#1#
#2#
meaning it is replacing "CATEGORY" but not the hash's (#)
I'm new to regex's so I'm pretty sure I'm doing something wrongand using preg_replace to fill in the data.
It's almost working except for one thing
my html is simple, it looks like this:
Code: Select all
<tr>
<td colspan="5">#CATEGORY#</td>
</tr>Code: Select all
//The HTML file
$header_array = file("e;header.html"e;);
$header = implode("e;"e;, $header_array);
//Information from the database
$category = $rowї'category'];
//preg_re
my html is simple, it looks like this:Code: Select all
<tr>
<td colspan="5"e;>#CATEGORY#</td>
</tr>Code: Select all
//The HTML file
$header_array = file("e;header.html"e;);
$header = implode("e;"e;, $header_array);
//Information from the database
$category = $rowї'category'];
//preg_replace function
print preg_replace("e;#CATEGORY#&qu need, and using preg_replace to fill in the data.
It's almost working except for one thing
my html is simple, it looks like this:Code: Select all
<tr>
<td colspan="e;5"e;>#CATEGORY#</td>
</tr>Code: Select all
//The HTML file
$header_array = file("header.html");
$header = implode("", $header_array);
//Information from the database
$category = $row['category'];
//preg_replace function
print preg_replace("#CATEGORY#", $category, $header);#1#
#2#
meaning it is replacing "CATEGORY" but not the hash's (#)
I'm new to regex's so I'm pretty sure I'm doing something wrong