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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.