set cookie value in javascript and displaying it with php

Set in javascript

document.cookie='fcookie='+tempo; 

Get in PHP

if (isset($_COOKIE["fcookie"])) 
echo $_COOKIE["fcookie"]; 
else 
echo "Cookie Not Set";

Change url parameters using javascript

var newUrl = your url
history.pushState({}, null, newUrl);

how to use in_array in smarty

in_array in smarty


{if $variable|in_array:[14, 15, 18]}

... Your code

{/if}


Or


in_array in smarty


{if $variable|in_array:$array}

... Your code

{/if}




Convert PDF to Text in PHP

<?php function pdf2string($sourcefile) { $fp = fopen($sourcefile, 'rb'); $content = fread($fp, filesize($sourcefile)); fclose($fp); $searchstart = 'stream'; $searchend = 'endstream'; $pdfText = ''; $pos = 0; $pos2 = 0; $startpos = 0; while ($pos !== false && $pos2 !== false) { $pos = strpos($content, $searchstart, $startpos); $pos2 = strpos($content, $searchend, $startpos + 1); if ($pos !== false && $pos2 !== false){ if ($content[$pos] == 0x0d && $content[$pos + 1] == 0x0a) { $pos += 2; } else if ($content[$pos] == 0x0a) { $pos++; } if ($content[$pos2 - 2] == 0x0d && $content[$pos2 - 1] == 0x0a) { $pos2 -= 2; } else if ($content[$pos2 - 1] == 0x0a) { $pos2--; } $textsection = substr( $content, $pos + strlen($searchstart) + 2, $pos2 - $pos - strlen($searchstart) - 1 ); $data = @gzuncompress($textsection); $pdfText .= pdfExtractText($data); $startpos = $pos2 + strlen($searchend) - 1; } } return preg_replace('/(\\s)+/', ' ', $pdfText); } function pdfExtractText($psData){ if (!is_string($psData)) { return ''; } $text = ''; // Handle brackets in the text stream that could be mistaken for // the end of a text field. I'm sure you can do this as part of the // regular expression, but my skills aren't good enough yet. $psData = str_replace('\\)', '##ENDBRACKET##', $psData); $psData = str_replace('\\]', '##ENDSBRACKET##', $psData); preg_match_all( '/(T[wdcm*])[\\s]*(\\[([^\\]]*)\\]|\\(([^\\)]*)\\))[\\s]*Tj/si', $psData, $matches ); for ($i = 0; $i < sizeof($matches[0]); $i++) { if ($matches[3][$i] != '') { // Run another match over the contents. preg_match_all('/\\(([^)]*)\\)/si', $matches[3][$i], $subMatches); foreach ($subMatches[1] as $subMatch) { $text .= $subMatch; } } else if ($matches[4][$i] != '') { $text .= ($matches[1][$i] == 'Tc' ? '' : '') . $matches[4][$i]; } } // Translate special characters and put back brackets. $trans = array( '...' => '…', '\\205' => '…', '\\221' => chr(145), '\\222' => chr(146), '\\223' => chr(147), '\\224' => chr(148), '\\226' => '-', '\\267' => '•', '\\(' => '(', '\\[' => '[', '##ENDBRACKET##' => ')', '##ENDSBRACKET##' => ']', chr(133) => '-', chr(141) => chr(147), chr(142) => chr(148), chr(143) => chr(145), chr(144) => chr(146), ); $text = strtr($text, $trans); return $text; } $sourcefile = '16.pdf'; $get = pdf2string($sourcefile); echo utf8_encode($get);

php curl request

function makeCURLRequest($url, $method="GET", $params = "") {
        if ($method == "GET" && strpos($url, '?')) {
            $urlParams = substr($url, strpos($url, '?')+1);
            $url = substr($url, 0, strpos($url, '?'));
            if (is_array($params)) {
                parse_str($urlParams, $urlParamsArray);
                $params = $urlParamsArray + $params;
            } else {
                $params = $urlParams.'&'.$params;
            }
        }
        if (is_array($params)) {
            $params = http_build_query($params,'','&');
        }
        $curl = curl_init($url . ($method == "GET" && $params != "" ? "?" . $params : ""));
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($curl, CURLOPT_HEADER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_HTTPGET, ($method == "GET"));
        curl_setopt($curl, CURLOPT_POST, ($method == "POST"));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
        curl_setopt($curl, CURLOPT_TIMEOUT, 30);
        if ($method == "POST") {
            curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
        }
       
        $response = curl_exec($curl);
        return $response;
    }

Magento 2 basic command


1) clear cache  :  php bin/magento cache:flush

2) reindex :  php bin/magento indexer:reindex

3) cmd to deploy static data  :  php bin/magento setup:static-content:deploy  en_US en_AU

4) show which mode is active developer or production

         php bin/magento deploy:mode:show

        set developer mode :  php bin/magento deploy:mode:set developer
        set production mode :php bin/magento deploy:mode:set production

5) check module status
     php bin/magento module:status

6) Enable module
       php bin/magento module:enable Your_modulename --clear-static-content
       eg. php bin/magento module:enable Rain_Affiliate --clear-static-content

7) Dissable module
      php bin/magento module:disable Magento_Weee

8 ) After install module  you have to run this 2  command
        php bin/magento setup:upgrade
        php bin/magento setup:di:compile

magento 2 regenerate product url php code

please follow the step as i show below

1) backup you database 

2) create one controller name Producturl.php

3) copy my code into that controller 


<?php  

namespace Company\Module\Controller\Producturl;


use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
use Magento\Store\Model\Store;

class Producturl extends \Magento\Framework\App\Action\Action
{
       public function execute()
    { 
           //// for regenerate product url /////////////////
             $objectManager = \Magento\Framework\App\ObjectManager::getInstance();   
             $this->collection = $objectManager->create('\Magento\Catalog\Model\ResourceModel\Product\Collection');

             $this->productUrlRewriteGenerator = $objectManager->create('\Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator');
             
             $this->urlPersist = $objectManager->create('\Magento\UrlRewrite\Model\UrlPersistInterface');

             $this->collection->addAttributeToSelect(['url_path', 'url_key']);
              $list = $this->collection->load();
              $store_id=1; // your store id 
              
              foreach($list as $product) {                
                      if($store_id === Store::DEFAULT_STORE_ID)
                          $product->setStoreId($store_id);
                      $this->urlPersist->deleteByData([
                          UrlRewrite::ENTITY_ID => $product->getId(),
                          UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
                          UrlRewrite::REDIRECT_TYPE => 0,
                          UrlRewrite::STORE_ID => $store_id
                      ]);
                      try {
                          $this->urlPersist->replace(
                              $this->productUrlRewriteGenerator->generate($product)
                          );
                      } catch(\Exception $e) {
                          $out->writeln('<error>Duplicated url for '. $product->getId() .'</error>');
                      }
              }
    }


}


?>