Jump to content


Photo

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


  • Please log in to reply
3 replies to this topic

#1 just-j

just-j
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts

Posted 26 July 2006 - 01:19 PM

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

#2 ozPATT

ozPATT
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 26 July 2006 - 01:39 PM

any more information you can provide? i dont really understand what you are wanting to achieve...

#3 just-j

just-j
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts

Posted 26 July 2006 - 01:49 PM

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++;
}
i want it to end up with $usermsg1 = blablabla  $usermsg2 = blablabalablablab ect......
$counter = 1;
while ($counter <= $ar) {
echo wordwrap($usermsg . $counter, 70, '<br />');
$counter++;
}
and this is used to print it all out line by line

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 26 July 2006 - 02:02 PM

Wouldn't it be much easier to use an array here:
<?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);
}?>
Then to use this:
<?php
foreach ($usermsg as $msg)
    echo wordwrap($msg,70,'<br />');
?>

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

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users