How to safely output HTML from a PHP program?

You always want to HTML-encode things inside HTML attributes, which you can do with htmlspecialchars: <span title=”<?php echo htmlspecialchars($variable); ?>”> You probably want to set the second parameter ($quote_style) to ENT_QUOTES. The only potential risk is that $variable may already be encoded, so you may want to set the last parameter ($double_encode) to false.

Print the keys of an array

You can use PHP’s array_keys function to grab the keys, like so: foreach(array_keys($parameters) as $paramName) echo $paramName . “<br>”; Or, you can run through the array using a special foreach which allows you to separate the key and value for every element, like so: foreach($parameters as $paramName => $value) echo $paramName . “<br>”; Also, make … Read more

Strip off specific parameter from URL’s querystring

The safest “correct” method would be: Parse the url into an array with parse_url() Extract the query portion, decompose that into an array using parse_str() Delete the query parameters you want by unset() them from the array Rebuild the original url using http_build_query() Quick and dirty is to use a string search/replace and/or regex to … Read more

Send JSON POST request with PHP

You can use CURL for this purpose see the example code: $url = “your url”; $content = json_encode(“your data to be sent”); $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array(“Content-type: application/json”)); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $content); $json_response = curl_exec($curl); $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ( $status != 201 ) { … Read more

How to change public folder to public_html in Laravel

Quite easy to find this with a simple search. See: https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-laravel-5 In your index.php add the following 3 lines. /* |————————————————————————– | Turn On The Lights |————————————————————————– | | We need to illuminate PHP development, so let us turn on the lights. | This bootstraps the framework and gets it ready for use, then it … Read more

How Can I Remove “public/index.php” in the Laravel Url generated? [duplicate]

Option 1: Use .htaccess If it isn’t already there, create an .htaccess file in the Laravel root directory. Create a .htaccess file your Laravel root directory if it does not exists already. (Normally it is under your public_html folder) Edit the .htaccess file so that it contains the following code: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule … Read more

tech