Skip to content

Instantly share code, notes, and snippets.

View rajvanshipradeep15's full-sized avatar

Pradeep Rajvanshi rajvanshipradeep15

  • India
View GitHub Profile
@rajvanshipradeep15
rajvanshipradeep15 / clean html when compiler process only php code not html
Created March 29, 2017 15:39
clean html when compiler process only php code not html
function clean($str)
{
$str = utf8_decode($str);
$str = str_replace(" ", "", $str);
$str = preg_replace("/\s+/", " ", $str);
$str = trim($str);
return $str;
}
<?php
error_reporting( E_ALL );
ini_set('display_errors', 1);
include 'Database.php';
$db = new Database();
$data = $db->getRecords();
$newData = array();
// your code goes here
$array = array(1,2,2,4,5);
$uniqueme = array();
$duplicates = array();
foreach ($array as $key => $value) {
if( false == in_array($value,$uniqueme) ) {
$uniqueme[] = $value;
} else {
@rajvanshipradeep15
rajvanshipradeep15 / get current url
Created February 1, 2017 07:17
get current url
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
echo $url; // Outputs: Full URL
@rajvanshipradeep15
rajvanshipradeep15 / validate pdf password protection
Created January 2, 2017 12:06
validate pdf password protection
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once './vendor/setasign/fpdi/pdf_parser.php';
if( 1 == $_GET['file'] ) {
//file which we need to open in browser.
$filename="pdf_sample.pdf";
@rajvanshipradeep15
rajvanshipradeep15 / download pdf inline and attachment
Created January 2, 2017 10:25
download pdf inline and attachment
<?php
if( 1 == $_GET['file'] ) {
//file which we need to open in browser.
$filename="pdf_sample.pdf";
$header="Content-Disposition: inline; filename=$filename;"; // Send File Name
} else {
//password protected file
$filename="pdf_sample_protected.pdf";
$header="Content-Disposition: attachment; filename=$filename;"; // Send File Name
Calculating web content cache size…Calculating web content cache size…
@rajvanshipradeep15
rajvanshipradeep15 / star program
Created December 12, 2016 16:38
star program
<?php
// your code goes here
// problem 01 solution
for($i=5;$i>=1;$i--)
{
echo str_repeat('*',$i);
echo "\n";
}
@rajvanshipradeep15
rajvanshipradeep15 / Finding the duplicate number
Created November 15, 2016 16:01
Finding the duplicate number with O(n) time complexity
function findDuplicateNumber( $number )
{
$count = count($number);
$duplicateNumber = 0;
for( $i = 0; $i < $count; $i++ )
{
if( $number[abs($number[$i])] >= 0 ) {
$number[abs($number[$i])] = -$number[abs($number[$i])];
} else {
@rajvanshipradeep15
rajvanshipradeep15 / reverse string with max N 2 iteration
Created November 12, 2016 05:49
reverse string with max N 2 iteration
<?php
function reverse($str)
{
for ($i = 0, $j = strlen($str) - 1; $i < $j; $i++, $j--) {
$tmp = $str[$i];
$str[$i] = $str[$j];
$str[$j] = $tmp;
$iteration++;