Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Sunday, 28 July 2013

PHP get file contents utf8 example

<?php
 $url = "http://ta.wikipedia.org/wiki/%E0%AE%AE%E0%AF%81%E0%AE%A4%E0%AE%B1%E0%AF%8D_%E0%AE%AA%E0%AE%95%E0%AF%8D%E0%AE%95%E0%AE%AE%E0%AF%8D";
 $string = file_get_contents($url);
// echo $string;
 $string = mb_convert_encoding($string, 'HTML-ENTITIES', "UTF-8");
 $dom = new DOMDocument();
 $dom->preserveWhiteSpace = false;
 $dom->encoding = 'UTF-8';
 $dom->loadHTML($string);
 $mock = new DOMDocument();

 $body = $dom->getElementsByTagName('body')->item(0);
 foreach ($body->childNodes as $child){
  $mock->appendChild($mock->importNode($child, true));
 }
 $html_content = $mock->saveHTML();
 $html = preg_replace('#<script(.*?)>(.*?)</script>#is','', $html_content);
 $html = preg_replace('#<style(.*?)>(.*?)</style>#is','', $html);
 
 $cont = preg_replace("/<.*?>/","",$html);
 
 echo $cont ;
?>



Related Tags :  Php crawl hindi language html content , php crawl tamil html content , PHP crawl utf-8 content.

Sunday, 21 July 2013

PHP php_printer.dll Installation and Configuration


1. Download xampp Server from http://www.oldapps.com/xampp.php?old_xampp=44

2. Install it

3. Goto Xammp Home directory (ex C:\Xampp)

4. Then open php flder

5. Then open php.ini file.

6. Find ;extension=php_printer.dll

7. Then Remove ";"

8. Done

Without Xampp users

1. Download lates php_print.dll from http://us.php.net/get/pecl-5.2.6-Win32.zip/from/a/mirror

2. After download and extract, you get php_print.dll.

3. Copy this dll and goto your php\ext directory and paste it.

4. Then open php.ini file.

5. Find (extension_dir="C:\Program Files\PHP\ext") on that file.

6. The add this line (extension=php_printer.dll) line.

7. DOne


Example for php print to printer example.

<?php
$printer = "\\\\servername\\printername";
$handle = printer_open($printer);
        printer_set_option($handle, PRINTER_MODE, "raw");
printer_set_option($handle, PRINTER_PAPER_FORMAT, PRINTER_FORMAT_A5);
$output = "Print Contents";
printer_write($handle,$output);
    printer_close($handle);
?>

PHP Multithreading Example and php_pthreads Configurataion

If Php Support Multithreading means you must configure following things

1. Download Php with Thread Safe from http://windows.php.net/download/

2. After Php installation, download pthreads libraries from http://windows.php.net/downloads/pecl/releases/pthreads/

3. After download and extraction , copy php_pthreads.dll and pthreadVC2.dll this files.

4. Then goto your Php\ext directory and paste it.

5. Then  goto your PHP directory and find and rename "php.ini-development" file to "php.ini".

6. Open php.ini file in Notepad and find ;extension=php_shmop.dll line and add extension=php_pthreads.dll after that line.

7. Then Find ;extension_dir = "ext" line and remove ; from that line.

8. Finaly Save that php.ini file

9. Done

Then Run Below Multithreading Example.


PHP Multithreading Example

<?php
class MultiThread_EX extends Thread
{
    public function __construct($arg)
    {
        $this->arg = $arg;
    }

    public function run()
    {
        if($this->arg){
            printf("Hello %s\n", $this->arg);
        }
    }
}

$thread = new MultiThread_Ex("World");
if($thread->start())
$thread->join();



Related Posts Plugin for WordPress, Blogger...