just-j Posted July 26, 2006 Share Posted July 26, 2006 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 Quote Link to comment Share on other sites More sharing options...
ozPATT Posted July 26, 2006 Share Posted July 26, 2006 any more information you can provide? i dont really understand what you are wanting to achieve... Quote Link to comment Share on other sites More sharing options...
just-j Posted July 26, 2006 Author Share Posted July 26, 2006 [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 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 26, 2006 Share Posted July 26, 2006 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]<?phpforeach ($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.phpKen Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.