Alle Funktionen in einem String erkennen

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Alle Funktionen in einem String erkennen

    Hat jemand eine Idee wie ich an die Funtionsnamen komme die in einem String verwendet werden?
    Beispiel
    PHP Code:
    <?php
    $str 
    "
    <?php
     
    $test = \"hallo welt\";
     echo ucwords (
    $test);
    ?>
    Bei diesem String hätte ich als Ergebnis gern
    Array[0] = echo
    Array[1] = ucwords

    Alternativ wär mir auch geholfen wenn jemand eine Idee hat wie ich ALLE Funktionsnamen in ein Array kriegen würde...

    Danke im Voraus
    PHP Code Schnipsel

  • #2
    1. des unterschieds zwischen " und ' bist du dir bewusst?
    2. reguläre ausdrücke wären das, was du brauchst. php.net/pcre

    aber wozu der umstand? evtl. brauchst du sowas wie highlight_string?

    Comment


    • #3
      du verstehst mich falsch
      highligth string benutz ich schon
      Aber egal wies der Zufall so will hab ich die funktion get_defined_functions () gefunden
      Aber ich danke dir herzlich für deine Mühe
      PHP Code Schnipsel

      Comment


      • #4
        Blöde Frage: Wozu soll das gut sein ?

        Comment


        • #5
          Ich hab ne PHP Code Schnipsel Datenbank und wil Links auf die darin verwendeten Funktionen setzten
          Aber so richtig Zuverlässig find ich die Funktionen noch nicht...
          Hat jemand eine Idee wie man sowas mit regulären Ausdrücken erledigt?
          Wäre um Hilfe doch noch dankbar...
          Mein Code bis jetzt:
          PHP Code:

          $functions 
          get_defined_functions();
             foreach (
          $functions as $function)
             {
               if (
          strpos($row["code"], $function."(") || strpos ($row["code"], $function." ("))
               {
                 
          $function str_replace ("_""-"$function);
                 
          $used_functions[] = "<a target=\"_blank\" class=\"content_light\" href=\"http://ch2.php.net/manual/de/function.$function.php\">$function</a>";
               }
             } 
          Last edited by Foggy; 13-03-2005, 16:13.
          PHP Code Schnipsel

          Comment


          • #6
            Hm genau genommen hab ich nur noch ein Problem.
            Und zwar Funktionen wie strpos () wird auch als Funktion pos () erkannt.
            Weiss jemand wie ich da Abhilfe schaffen kann?
            Mein Code jetzt:
            PHP Code:
            //Die Funktion die mir alle Funktionen in ein Array schreiben soll: 
            function get_functions ()
            {
                
            $functions get_defined_functions ();
                foreach (
            $functions["internal"] as $function)
                {
                 if (
            function_exists ($function))
                  
            $funcs[] = $function;
                }
                return 
            $funcs;
            }
            //Array functions belegen
               
            $functions get_functions();
            //Die fehlenden Funktionen hinzufügen
               
            $functions[] = "isset"
            //Funktionen ohne ()
               
            $functions_whout[] = "return"
               
            $functions_whout[] = "echo"
               
            $functions_whout[] = "print"
            //Kontroll Strukturen
               
            $contol_structures[] = "else";
               
            $contol_structures[] = "elseif";
               
            $contol_structures[] = "while";
               
            $contol_structures[] = "do.while";
               
            $contol_structures[] = "for";
               
            $contol_structures[] = "foreach";
               
            $contol_structures[] = "break";
               
            $contol_structures[] = "continue";
               
            $contol_structures[] = "switch";
               
            $contol_structures[] = "declare";
               
            //$contol_structures[] = "return";
               
               
            foreach ($functions as $function)
               {
                 if (
            strpos($row["code"], $function."(") || strpos ($row["code"], $function." ("))
                 {
                   
            $function str_replace ("_""-"$function);
                   
            $used_functions[] = "<a target=\"_blank\" class=\"content_light\" href=\"http://ch2.php.net/manual/de/function.$function.php\">$function</a>";
                 }
               }
               foreach (
            $functions_whout as $function)
               {
                 if (
            strpos ($row["code"], $function))
                   
            $used_functions[] = "<a target=\"_blank\" class=\"content_light\" href=\"http://ch2.php.net/manual/de/function.$function.php\">$function</a>";
               }
               foreach (
            $contol_structures as $control)
               {
                 if (
            strpos ($row["code"], $control))
                   
            $used_controls[] = "<a target=\"_blank\" class=\"content_light\" href=\"http://ch2.php.net/manual/de/control-structures.$control.php\">$control</a>";
               } 
            kann mir jemand sagen wie ich unterbinden kann das mir mein Code bspw die Funktion strpos () auch als Funktion pos () erkennt?
            Für Hilfe wär ich wirklich sehr dankbar...
            PHP Code Schnipsel

            Comment


            • #7
              brich bitte deinen code um.

              der unterschied zwischen strpos und pos wäre aus der sicht eines regulären ausdrucks der, dass vor dem funktionnamen ("pos") ein nicht-alphanummerisches zeichen vorhanden ist.

              Comment


              • #8
                Ja klar das ist es ich danke dir Penizillin
                PHP Code Schnipsel

                Comment

                Working...
                X