Is there a function in PHP to which I can pass an HTTP status code as an argument, and it will return the textual representation of the status code? For example, if I pass 404, it will return Not Found, 301 - Moved Permanently, 200 - OK, and so on.
Asked
Active
Viewed 58 times
0
-
4You have to use another function for this... Maybe that could help... https://gist.github.com/danmatthews/1379769 – tanaydin Jun 11 '18 at 12:36
-
I wish there was a native way to do this, but oh well. Thanks for the function! – Jeff Jun 11 '18 at 12:37
-
1https://stackoverflow.com/questions/3258634/php-how-to-send-http-response-code?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Masivuye Cokile Jun 11 '18 at 12:39
-
You could very easily build your own mapping/enumeration for this. Doh! @tanaydin's example above seems to already be complete. – scunliffe Jun 11 '18 at 12:41
-
No there's no built-in way to get this you have to write your own. Just go to https://en.wikipedia.org/wiki/List_of_HTTP_status_codes and map those codes to their messages – apokryfos Jun 11 '18 at 12:44
-
http://php.net/manual/en/function.http-response-code.php#107261 – MonkeyZeus Jun 11 '18 at 12:46
-
@MonkeyZeus in your example it returns as "HTTP header" but Jeff needs it to return as "text". Small difference, big changes. – tanaydin Jun 11 '18 at 12:49
-
@tanaydin The comment which I linked to has text responses per code. It can effortlessly be modified to suit OP's needs. – MonkeyZeus Jun 11 '18 at 13:01
-
Yeah, that is why I haven't mentioned as the first comment. – tanaydin Jun 11 '18 at 13:03