0

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

2
  • Set error_reporting and display_errors so you see what you are doing wrong. And quote 'HH' Commented Aug 15, 2014 at 11:46
  • Ah, yet another code with funky quotes ‘ ’. "Beautiful, yet deadly." Commented Aug 15, 2014 at 12:41

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

and thats why working in early hours is never a good thing, can't believe i missed that thanks
1

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

2 Comments

the quote marks in the include are still wrong in this example, they need to be single or double, not back ticks
Oh sorry i did it by mistake
1

include expects double quotes " so change that in, your code and it should work. include "Play.php";

Comments

-2

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.