开发者

Warning: file_get_contents(text.php?text=a-e) [function.file-get-contents]: failed to open stream: No error in

if(isset($_GET['letters'])){
                        switch($_GET['letters']){
                            case 'a-e':
                                file_get_contents('text.php?text=开发者_运维问答a-e');
                                break;

                            case 'f-j':
                                file_get_contents('text.php?text=f-j');
                                break;

                            case 'k-o':
                                file_get_contents('text.php?text=k-o');
                                break;

                            case 'p-t':
                                file_get_contents('text.php?text=p-t');
                                break;

                            case 'u-z':
                                file_get_contents('text.php?text=u-z');
                                break;

                            default:
                                file_get_contents('home.php');
                                break;
                        }
                    }

In this code i get this error:

Warning: file_get_contents(text.php?text=a-e) [function.file-get-contents]: failed to open stream: No error in *(the row of the file_get_contents())*

I also tried include. But it doesn't work?


You can't pass parameters to a file on opening from your script. This can be done when sending an HTTP request for a page to the server, but not in this case.

Also, beware that switch cases must be atomic. For example, if $_GET['letters'] was 'b', none of your switch cases would execute.

I can't tell from your post exactly what you're trying to do. If you're storing your text in flat files, use a better suffix, such as ".txt". One approach would be to have multiple files, each corresponding to a category (e.g. 'a-e'). You would set your file name in the switch statement.

If on the other hand you're trying to call code in your switch, file_get_contents is not the function to use. Use 'require_once 'my_file.php' instead.


there is no file 'text.php?text=u-z' on your disk.

just change your link parameter from ?letters to ?text and then make it

if(isset($_GET['text'])){
    include('text.php');
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜