Hey guys :)
I
Printable View
Hey guys :)
I
while($i < 5)
{
$i = 1;
$i = $i++;
echo $i;
}
This will add +1 to the I var. it will echo 1 2 3 4 5 then stop... This is what I think your saying you need $i to +1 to have like 1: this 2: this 3: this so on so forth?
i know how to use $i++ but i have no idea how to use it in that special case.
Each time preg_replace is executed $i should raise by one. How can i tell preg_replace to raise $i by one each time it finds "area x" ?
while($str = preg_replace("!(area(.)[0-9]*)!","area $i",$text);)
{
$i = $i++;
}
I think that'd work?
had almost the same idea, but those wonQuote:
PHP Code:while($str = preg_replace("!(area(.)[0-9]*)!","area $i",$text))
{
$i = $i++;
}
how about spliting the text into lines and the use preg_replace or ereg_replace
cause if $text is whole text then it replace all text, but if you would have a loop that would
convert line by line...
take care.PHP Code:
$lines = explode("\n", $text);
foreach($lines as $var) {
/*
you code wich would increment the $i
and do rest whatever you would need
also i'm not sure how the files were encdoded so try with \n and if it won't work
try with \r
*/
}
[B]DanseMacabre very nice :)
But it gives me just the first line back. 0o
Any clue ? but i think we
eh it gives you only one line cause you are not appending the text into the variable named $str
it shall be
now please note the coma symbol before equation symbol, as the coma is very important so you would get all your records not just first or last one.PHP Code:foreach($lines as $var) {
$i = $i++;
$str .= preg_replace("!(area(.)[0-9]*)!","area $i",$var);
/* no look for the coma up there it's very important cause it will append each line
into variable not overwrite it
*/
}
echo $str;
almost :) didn