Returning JSON from a PHP Script

While you’re usually fine without it, you can and should set the Content-Type header: If I’m not using a particular framework, I usually allow some request params to modify the output behavior. It can be useful, generally for quick troubleshooting, to not send a header, or sometimes print_r the data payload to eyeball it (though in most cases, it … Read more

Returning JSON from a PHP Script

While you’re usually fine without it, you can and should set the Content-Type header: If I’m not using a particular framework, I usually allow some request params to modify the output behavior. It can be useful, generally for quick troubleshooting, to not send a header, or sometimes print_r the data payload to eyeball it (though in most cases, it … Read more

Insert string at specified position

http://php.net/substr_replace In the above snippet, $pos is used in the offset argument of the function. offsetIf offset is non-negative, the replacing will begin at the offset’th offset into string. If offset is negative, the replacing will begin at the offset’th character from the end of string.

PHP – setcookie(); not working

You have to set cookies before any headers are sent out. From the manual: setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to … Read more

PHP: fopen() Permission denied

I am confused with this code: test.php: when I execute it, I get an error: test.txt: where is the problem? Thanks a lot!I have found the problem,I use FC13,because of the protect of SELinux,some action is denied.So, I just need to get rid of the protect.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)