简体   繁体   中英

How to call a php function from another php file

I have two php files, one index.php

<?php
    include ‘Play.php’;
    $temp = first(HH);
    echo $temp;
?>

second Play.php

<?php
    function first($string)
    { 
            return $string;  
    }
?>

if i remove $temp = first(HH); from the first file then it works, if i include it, the index.php don't work (don't show anything on the screen when i call it within safari.

I know its going to be obvious but what am i doing wrong? Both files are in the same file directory.

Thanks

Use the right kind of quotes around your string for the include. " or ' not ' and ' .

The use of typographic quotes like that suggests you may be trying to write code with a word processor. Don't do that; get a text or code editor instead.

Your function is right but the way you are calling your function is not correct.And the way you are including the file is incorrect. You should include your file in quotes like "" or '' . You have to enclose the string in quotes "" . Use the code below in index.php

<?php
    include 'Play.php';
    $temp = first("HH");
    echo $temp;
?>

I hope this helps you

include预计双引号" ,从而改变在,你的代码,它应该工作。 include "Play.php";

Kindly change $temp = first(HH); to $temp = first("HH");

its is because your function tack string as a parameter you should send a string

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM