Jump to content

Archived

This topic is now archived and is closed to further replies.

just-j

having trouble with a with setting a var with a counting number

Recommended Posts

ok i want the variable name to to go up by one like $var1 $var2 $var3.  i have the loop but this "$usermsg . $ar = str_replace($htmlcode, "",$text);" isnt working..  it is setting $ar to the variable

Share this post


Link to post
Share on other sites
any more information you can provide? i dont really understand what you are wanting to achieve...

Share this post


Link to post
Share on other sites
[code]
foreach ($lines as $line_num => $line) {
$text = $line;
if ($text == "") { $text = "-"; }
if (strpos($text, "92239182") === false) { $go1 = "no"; } else { $go1 = "yes"; }
if (strpos($text, "92239180") === false) {  $go2 = "no"; } else { $go2 = "yes"; }
if (strpos($text, "mmmmsgstart") === false) {  $go3 = "no"; } else { $go3 = "yes"; }
if (strpos($text, "mmmmsgend") === false) {  $go4 = "no"; } else { $go4 = "yes"; }
if ($go1 == "no" && $go2 == "no" && $go3 == "no" && $go4 == "no") {
$htmlcode = array("<", ">");
$usermsg . $ar = str_replace($htmlcode, "",$text);
$ar++;
}
[/code]
i want it to end up with $usermsg1 = blablabla  $usermsg2 = blablabalablablab ect......
[code]
$counter = 1;
while ($counter <= $ar) {
echo wordwrap($usermsg . $counter, 70, '<br />');
$counter++;
}
[/code]
and this is used to print it all out line by line

Share this post


Link to post
Share on other sites
Wouldn't it be much easier to use an array here:
[code]<?php
$usermsg = array();
foreach ($lines as $line_num => $line) {
$text = $line;
if ($text == "") { $text = "-"; }
if (strpos($text, "92239182") === false) { $go1 = "no"; } else { $go1 = "yes"; }
if (strpos($text, "92239180") === false) {  $go2 = "no"; } else { $go2 = "yes"; }
if (strpos($text, "mmmmsgstart") === false) {  $go3 = "no"; } else { $go3 = "yes"; }
if (strpos($text, "mmmmsgend") === false) {  $go4 = "no"; } else { $go4 = "yes"; }
if ($go1 == "no" && $go2 == "no" && $go3 == "no" && $go4 == "no") {
$htmlcode = array("<", ">");
$usermsg[] = str_replace($htmlcode, "",$text);
}?>[/code]
Then to use this:
[code]<?php
foreach ($usermsg as $msg)
    echo wordwrap($msg,70,'<br />');
?>[/code]

BTW, what you are trying to do is known as using variable variables. See http://www.php.net/manual/en/language.variables.variable.php

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.