/    Sign up×
Community /Pin to ProfileBookmark

file_get_contents, catch error?

Umm, I got a file_get_contents function that get contents from a site depending on a variable in the url, if the variable makes a url that referrs to a site that doesn’t exist and which will return a 404 error.. I wondered how I could display for example: “Please enter a valid username!” instead of:

[code=php]Warning: file_get_contents(http://hiscore.runescape.com/index_lite.ws?player=ordbogk4) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not found in C:xampphtdocstehcalcsaction.php on line 10[/code]

The syntax I’m using is:

[code=php]$stats = file_get_contents(‘http://hiscore.runescape.com/index_lite.ws?player=’.$rsn);[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@STREETRULEZJun 16.2009 — hi norra =)

here is the command listing:

[code=php]
$stats = @file_get_contents('http://hiscore.runescape.com/index_lite.ws?player='.$rsn) or print('Please enter a valid username!');
[/code]




have phun =)


mfg maxx
×

Success!

Help @norra spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...