Skip to main content

Posts

Showing posts from March 18, 2018

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 :

Replace the last occurrence of an expression in a string

Code to  replace the last occurrence of an expression or string in another string using python. def rreplace (s, old, new, occurrence): li = s . rsplit(old, occurrence) print new . join(li) return new . join(li) rreplace( '123434352232' , '2' , '6' , 1 ) Output :

Reading and Generating QR codes in Python using QRtools

What are QR codes? A Quick Response (QR) code is a 2 dimensional barcode that is used due to its fast readability and relatively large storage capacity.  2 dimensional barcodes are similar to one dimensional barcodes, but can store more information per unit area. Installation and Dependencies Linux:   qrtools can be installed on debian based linux systems with the following commands $sudo apt-get update $sudo apt-get install python-qrtools The following dependencies must be installed as well [sudo] pip install pypng [sudo] pip install zbar [sudo] pip install pillow Windows:   qrtools can be installed on windows by downloading the file from here(https://pypi.python.org/pypi/qrtools/0.0.1). On downloading and extraction, run the following command from inside the folder python setup.py install Generating a qrCode: qrtools contains a class QR (can be viewed in the source code), for which we must initially create an object. The object takes the ...