WCM Forum

WCM Forum (http://www.wcm.at/forum/index.php)
-   Programmierung (http://www.wcm.at/forum/forumdisplay.php?f=17)
-   -   PHP - Problem (http://www.wcm.at/forum/showthread.php?t=242101)

ZombyKillah 17.05.2011 21:00

PHP - Problem
 
Hallo,
Ich hab einen Fehler und weiß einfach nicht mehr weiter.
Mein Code:
PHP-Code:

<?php
$usr
["web"]="www.page.com";
$usr["name"]="Zomby ";
$usr["fam"]="Killah ";
$out "new/";
$in "template/";
$template[]="templ1";
if(isset(
$usr)){
    foreach (
$template as $tpl){
        
$files[]="$tpl.txt";                //Files that needs to be changed (content: %usr:web%)
        
$files[]="$tpl.htm";
        foreach (
$files as $file) {
            
$fhin fopen("$in$file""r");
            if (
$fhin) {
                if (
$out != "") if (!check_folder($out)) echo "FOLDER $out couldn't be created!\n";
                else {
                    
$fhout fopen("$out$file""w+");
                    if (
$fhout) {
                        while ((
$line fgets($fhin)) == true) {                //Read Next line if possible
                            
$vars explode("%"$line);                        //Search for %
                            
$i 1;
                            
$new_line="";                                        //No new line
                            
if (count($vars)%== 1) { while (isset($vars[$i])) {    //If the amount of % can be right
                                
$poss_string $vars[$i];                        //Just check entrys between %
                                
$search explode(":"$poss_string);            //Look if they have a :
    //                            print_r($search);                                
                                
if (!isset($search[1])) $new_line.=$poss_string;//whoops - error - line shall not change
                                
elseif ($search[0]!="") {                        //Check if a $search[0] has a value
                                    
$name trim($search[0]);                    //Remove all additional invesible chars
                                    
if ($name == "usr") echo "Name is urs!!\n";    //WTF?!
                                    
else echo "$name !== usr\n";
        
//                            $name = "usr";                                
    //                                echo "looking for $name:".$search[1]."\n";
                                    //echo "$usr";
                                    
print_r (${$name});
                                }
                                
$i+=2;
                            } }else 
$new_line $line;
                            if (
$new_line != "") {
                            
                                
fputs($fhout$new_line);
                            }
                        }
                        
fclose($fhout);
                    } else echo 
"Signature $tpl file: $file couldn't be created\n";
                }
                
fclose($fhin);
            } else echo 
"Template $tpl file: $file not found\n";
        }
    }
}

function 
check_folder($dir){
    if (
$dir == "") return false;
    if (
is_dir($dir)) return true;
    if (
mkdir($dir)) return true;
    
$dirs explode("/",$dir);
    unset(
$dirs[count($dirs)-1]);
    return 
check_folder(implode("/",$dirs));
}
?>

Ich will mit templates basteln, für Signaturen die folgender weise aussehen:
Code:

%usr:titel%%usr:name%%usr:fam%
%usr:abt%
 
%com:name%
%com:namesub%
%com:add1%
%com:add2%
%usr:handy%
%com:tel%
%com:web%

Dachte mir es ist am einfachsten, wenn ich die Werte die ich einsetzen will in Arrays schreibe und die Arrays einfach identifiziere.

Mein Problem:
Wenn "usr" aus dem File gelesen wird scheint es nicht verwendbar zu sein, um es als Variablennamen zu verwenden.
Bei den Code oben überprüfe ich ob "usr" (Aus dem File gelesen) == "usr" ist.

Scheinbar nicht ?!?!?
Was muss ich machen, damit es dass wird?!?

Result:
Zitat:

usr !== usr
PHP Notice: Undefined variable: u in /samba/lamp_log/apache/db/sigs/bug.php on line 32
usr !== usr
PHP Notice: Undefined variable: u in /samba/lamp_log/apache/db/sigs/bug.php on line 32
usr !== usr
PHP Notice: Undefined variable: u in /samba/lamp_log/apache/db/sigs/bug.php on line 32
usr !== usr
PHP Notice: Undefined variable: u in /samba/lamp_log/apache/db/sigs/bug.php on line 32
com !== usr
PHP Notice: Undefined variable: c in /samba/lamp_log/apache/db/sigs/bug.php on line 32
com !== usr
PHP Notice: Undefined variable: c in /samba/lamp_log/apache/db/sigs/bug.php on line 32
com !== usr
PHP Notice: Undefined variable: c in /samba/lamp_log/apache/db/sigs/bug.php on line 32
com !== usr
PHP Notice: Undefined variable: c in /samba/lamp_log/apache/db/sigs/bug.php on line 32
usr !== usr
PHP Notice: Undefined variable: u in /samba/lamp_log/apache/db/sigs/bug.php on line 32
com !== usr
PHP Notice: Undefined variable: c in /samba/lamp_log/apache/db/sigs/bug.php on line 32
com !== usr
PHP Notice: Undefined variable: c in /samba/lamp_log/apache/db/sigs/bug.php on line 32
Hat von euch wer eine Ahnung, was los ist?
Danke für Antwort,
Zomby

ZombyKillah 17.05.2011 21:27

Hab herausgefunden was ich machen muss:
PHP-Code:

$name trim($search[0]);
$name str_ireplace("\0","",$name); 

Scheinbar werden da ein paar Zeichen zwischen den Buchstaben noch ausgeblendet.


Alle Zeitangaben in WEZ +2. Es ist jetzt 18:52 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© 2009 FSL Verlag