Skip to main content

Posts

Convert HTML to PDF using mPDF library

PDF is format of file to share .Here is code for converting html to PDF using mpdf library (PHP library). //include library path include('mpdf/mpdf.php'); $mpdf=new mPDF('c','A4','','' , 0 , 0 , 0 , 0 , 0 , 0); $mpdf->SetDisplayMode('fullpage'); $mpdf->list_indent_first_level = 0; $mpdf->WriteHTML('<html><head></head><body><h2>Welecome to HTML to PDF </h2></body></html>'); //save the file put which location you need folder/filename $mpdf->Output('test.pdf', 'F'); You can download the library from GitHub. Extract it and paste into your (project folder).

Curl retrieval of page or url

Simple way of retrieving data from an URL  using CURL $curl = curl_init(); curl_setopt($curl,CURLOPT_URL,'https://esoftsolutions4u.blogspot.com'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($curl); $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl);

Easily search and use the commands that you had used in the past

Imagine a situation where you used a long command couple of minutes/hours ago and you have to use it again. Problem is that you cannot remember the exact command anymore. Reverse search is your savior here. You can search for the command in the history using a search term. Just use the keys ctrl+r to initiate reverse search and type some part of the command. It will look up into the history and will show you the commands that matches the search term. ctrl+r search_term By default, it will show just one result. To see more results matching your search term, you will have to use ctrl+r again and again. To quit reverse search, just use Ctrl+C.

Get parent element in jQuery

We often need access of parent elements in the DOM while using jQuery functions.This can be achieved by using element.parent(). Let us take some example: HTML Code: <div id= "div1" > <span> This is span </span> </div> jQuery Code: < script > $($document).ready( function (){ var par_id = ( "span" ).parent().attr( 'id' ); alert(par_id); }); < /script>

How to create a directory if not exists?

#!/usr/bin/python import os file_path = "/home/projects/filename.txt" dir = os . path . dirname(file_path) if not os . path . isdir( dir ) : os . makedirs( dir ) os.path.dirname returns the directory name of pathname path  Ex: os.path.dirname('/home/projects/filename.txt') will returns the directory name projects os.path.isdir returns True if path is an existing directory The method makedirs() is recursive directory creation function. Like mkdir(), but makes all intermediate-level directories needed to contain the leaf directory.

Replace the last occurrence of a string in a string using PHP

Code to replace the last occurrence of a string in a string using PHP <?php function str_lreplace ( $search , $replace , $subject ) { $pos = strrpos ( $subject , $search ); print $pos ; if ( $pos !== false ) { $subject = substr_replace( $subject , $replace , $pos , strlen ( $search )); } echo $subject ; return $subject ; } str_lreplace( 'hello' , 'world' , 'this is hello world for checking hello when hello' ); ?> output :