php bir dosya arama ve yürütme

7 Cevap

Bu garip gelebilir :)

i yani aşağıdaki linke tıklayarak zaman nasıl olurdu gibi dosyayı yürütün bir dosyayı (test_2.php) "çağırmak" için istiyorum:

<a href="home/test_2.php">click here</a>  //this code is currently in test_1.php file

Bunu yapmak için herhangi bir yöntem var mıdır?

7 Cevap

Ben linki tıkladığınızda ne demek idam almak için bu php istiyorum, düşünüyorum, ama sayfa / yeniden değiştirmek istemiyorum.

Ajax burada senin arkadaşın. Eğer Jquery kullanıyorsanız, javascript kodunun sadece bir satır onu yapacağım:

$.get('home/test_2.php', function(data, txt){ alert(txt); });

jQuery.get documentation. bu işlevi hakkında daha fazla oku

Şerefe!

Muhtemelen) (dahil arıyorsunuz?

http://php.net/manual/en/function.include.php

I Curl ne istediğiniz olduğunu düşünüyorum.

Sen dahil () isteyebilirsiniz?

http://php.net/manual/en/function.include.php

<?php
  include("test2.php"); //This is just like inserting test2.php's code in this file
  /* rest of the code */
?>

Ben sorun cevabınızı, özellikle bağlantı parçasını anlama yaşıyorum, ama sen belki dosyalar http://php.net/manual/en/function.include.php dahil demek?

Sunucu destekliyorsa, bir http:// URL hile yapmak ve tam olarak istenilen sonucu üretmek gerekir () kullanarak içerir.

Eğer bir dosya sistemi yolu eklerseniz (örneğin, include /home/sites/www.example.com/test.php) dosya ne istediğiniz olmayabilir hangi geçerli bağlamda parsed olacaktır.

Eğer bir komut dosyasını çalıştırmak ve bu çıkışı bulunuyor yakalamak demek? Bunun için ben aşağıdaki kullanın:

    /**
    *       Execute a php file and return it's output.
    *       The file will be executed in the script's context. 
    *       It is not sandboxed in any way and it can access the global scope.
    *
    *       @param  string  $file           The file to execute.
    *       @param  array   &$context       An optional array of name=>value 
    *                       pairs to define additional context.
    *       @return string  The file's output.
    */
    function execFile($file, &$context=NULL)
    {
            if(is_array($context)) 
            {
                    extract($context, EXTR_SKIP);
            }

            ob_start();
            include $file;
            $ret = ob_get_contents();
            ob_end_clean();
            return $ret;
    }

Eğer bu işlev için ne vermek dikkatli olun.