Asked  7 Months ago    Answers:  5   Viewed   30 times

How can I check if the function my_function already exists in PHP?

 Answers

95

Using function_exists:

if(function_exists('my_function')){
    // my_function is defined
}
Wednesday, March 31, 2021
 
Sagar
answered 7 Months ago
15
function round_up($value, $precision=0) {
    $power = pow(10,$precision);
    return ceil($value*$power)/$power;
}
function round_down($value, $precision=0) {
    $power = pow(10,$precision);
    return floor($value*$power)/$power;
}
Saturday, May 29, 2021
 
RenegadeAndy
answered 5 Months ago
92

Using java.io.File:

File f = new File(filePathString);
if(f.exists() && !f.isDirectory()) { 
    // do something
}
Tuesday, June 1, 2021
 
Ula
answered 5 Months ago
Ula
94

What about using Youtube's API?
After all, that would mean using some official, which is less likely to change than going with parsing some HTML page.

For more information: YouTube APIs and Tools - Developer's Guide: PHP

The Retrieving a specific video entry seems quite interesting: if you send a request to an URL like this one:

http://gdata.youtube.com/feeds/api/videos/videoID

(replacing "videoID" by the ID of the video, of course – "GeppLPQtihA" in your example), you'll get some ATOM feed if the video is valid; and "Invalid id" if it's not


And, I insist: this way, you rely on a documented API, and not on some kind of behavior that exists today, but is not guaranteed.

Thursday, June 3, 2021
 
Shibbir
answered 5 Months ago
22

add these code into the top of your script

@set_magic_quotes_runtime(false);
ini_set('magic_quotes_runtime', 0);
Wednesday, August 18, 2021
 
Warrior
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :