Jump to content

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


just-j

Recommended Posts

[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
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

Archived

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

×
×
  • Create New...

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.