Question:

PHP Error: Call to undefined function? Plz Help?

by  |  earlier

0 LIKES UnLike

Ok so im trying to call a function from a module that calls from a module. Lol dont get confused here,

Fatal error: Call to undefined function read_news()

Code:

<?php

// tried adding the global datatype before function... didnt work!

function read_news($filename,$max_words)

{

$file = file($filename ".txt");

for($a = 1; $a < $max_words; $a )

{

echo $file[$a] . " ";

}

}

?>

basically trying to call a function from a module, but its not locating it. I think it revolves around making the function global but i dont know how to do so, can anyone help me"?

Much Appreciated,

Aric

 Tags:

   Report

2 ANSWERS


  1. You should have a directive

    include_once(&quot;global.txt&quot;); on your PHP file, so you can call any functions defined on global.txt. Heres a sample:

    FILE NAME: global.txt

    &lt;?php

    function read_news($filename,$max_words)

    {

    $file = file($filename &quot;.txt&quot;);

    for($a = 1; $a &lt; $max_words; $a )

    {

    echo $file[$a] . &quot; &quot;;

    }

    }

    ?&gt;

    so, on your PHP script that needs to call read_news( ), you should have an :

    &lt;?php

    include_once(&quot;global.txt&quot;);

    // to do

    ?&gt;

    hope this helps


  2. You might want to try file_get_contents()

    http://us2.php.net/manual/en/function.fi...

    But to answer your question, there is no reason your function is not available.  Make sure it is ahead of all other code.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.