Jump to content

Kloplop321

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Posts posted by Kloplop321

  1. using

    $text = "LeftWidth =      16em\n";
    preg_match_all('/([a-zA-Z]*)\s*=(\s*?)([ a-zA-Z0-9]*)\n/i', $text, $result);
    $newvalue = "24em";
    
    $text = preg_replace('/([a-zA-Z]*)\s*=(\s*?)([ a-zA-Z0-9]*)\n/i', "$1=$2_REMOVE_$newvalue", $text);
    $text = str_replace("_REMOVE_",'',$text);
    echo "[$text]<br />\n";
    

    I can get the result you want.

    The reason why this happens is because when the text is parsed the "newvalue" variable exists so it puts in "$1=$224em\n"

    This is where preg_replace tries to parse it and may get confused by this. You could use a space instead of _REMOVE_ but then str_replace would so easily take out every space in the whole thing.

  2. you could do

    echo "$monthup <br>";
    echo "$monthdown <br>";
    $answer = (int)$monthup + (int)$monthdown;
    echo $answer;

    or

    $monthup = (int)trim($monthup);
    $monthdown = (int)trim($monthdown);
    echo "$monthup <br>";
    echo "$monthdown <br>";
    $answer = (int)$monthup + (int)$monthdown;
    echo $answer;

    You may need to cast them to numbers as an integer or a real number[ use (real) instead of (int)] before adding them together. if the variable has a space before the number by accident, trim() will remove it.

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