[SOLVED] Help with Preg_replace
Posted: Tue Feb 01, 2005 6:04 am
Hi. I've been trying to preg_replace the same string with different values each time, but preg_replace stores the first value it was given, and only the first value. When I try changing it(Trying with a loop, and tried manually too) it keeps the same value. So does str_replace.
Is there some way I can change the value of the string I replaced so that it replaces it with another value.
I'm only saying it cause I want to change {name}(from an html page, sort of like a template page) with the name of each tournament from the database.
Here's the code I'm using.
The html page($this->html) has the following code.
The script outputs the link to the last tournament on the database over and over again(6 times to be exact, the number of current tournaments in 'tournaments' table)
What should I do? how can I make preg_replace erase it's first value, and add another one the next loop.
Is there some way I can change the value of the string I replaced so that it replaces it with another value.
I'm only saying it cause I want to change {name}(from an html page, sort of like a template page) with the name of each tournament from the database.
Here's the code I'm using.
Code: Select all
$query = "SELECT * FROM tournaments ORDER BY id DESC";
$tourneys = $DB->Query($query);
while ($row = mysql_fetch_row($tourneys)) {
if ($row) {
$this->tournamentї'id'] = $rowї0];
$this->tournamentї'name'] = $rowї1];
$this->tournamentї'game'] = $rowї2];
$this->tournamentї'standings'] = $rowї3];
$this->tournamentї'winners'] = $rowї4];
foreach ($this->tournament as $key => $value) {
$this->html = preg_replace("/{".$key."}/", $value, $this->html);
}
echo $this->html;The html page($this->html) has the following code.
Code: Select all
<a href="tournament.php?id={id}">{name}</a>What should I do? how can I make preg_replace erase it's first value, and add another one the next loop.