Posts

Showing posts with the label php

php8 COM Exception Type Mistmtach in paramater #0 when calling MS Word COM object SaveAs

php8 COM Exception Type Mistmtach in paramater #0 when calling MS Word COM object SaveAs I saw this: https://bugs.php.net/bug.php?id=73605   When calling $word->SaveAs($filename, 8); You should change to $word->SaveAs($filename, new variant(8, VT_I4);    

php 8 using ldap connectivity configuring php.ini and apache2.4

Got an error that ldap_connect is not a recognize function to use with apache 2.4, php 8 on windows Here is a solution: 1. Enable extension=ldap in the php.ini 2. Copy .dll files from the php installation directory into the apache/bin installation directory Please note, ldap_sort function was deprecated

Enabling php error logging with caddy and php-fpm

How to enable php error logging with caddy and php-fpm Inside the file: pool.d/www.conf Edit at the end: php_admin_value[error_log] = /var/log/fpm-php.www.log php_admin_flag[log_errors] = on catch_workers_output = yes

Connecting to mysql with TLS 1.2 SSL encrypted connection

In order to be able to connect to MySQL remote server using encrypted connection overt TLS1.2 you will need a .pem certificate of CA.  You can obtain the certificate here: https://dl.cacerts.digicert.com/DigiCertGlobalRootCA.crt.pem (DigiCertGlobalRootCA.crt.pem) Read more here: https://docs.microsoft.com/en-us/azure/mysql/flexible-server/how-to-connect-tls-ssl Here is a PHP sample for connection with SSL to MySQL encrypted connection on TLS1.2: self::$mysqli = mysqli_init(); //self::$mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true); self::$mysqli->ssl_set(NULL, NULL, "DigiCertGlobalRootCA.crt.pem", NULL, NULL); self::$mysqli->real_connect(host', 'username', 'password', 'database'); // , 3306, MYSQLI_CLIENT_SSL); //self::$mysqli = new mysqli('hots', 'username', 'password', 'database');    self::$mysqli->set_charset('utf8'); return self::$mysqli; Here is the full certificate for M...

Using phpword to merge two Mircrosoft Office Word .docx documents

How to combine or embed and insert another .docx file (Microsoft office docx word document) into another one using PHPWord Joining two .docx document using php ( phpword library ) $mainTemplateProcessor = new \PhpOffice\PhpWord\TemplateProcessor("file1"); //$mainTemplateProcessor ->setValue('var_name', $value); $innerTemplateProcessor = new \PhpOffice\PhpWord\TemplateProcessor("file2"); //$innerTemplateProcessor->setValue('var2_name', $value2); // extract internal xml from template that will be merged inside main template $innerXml = $innerTemplateProcessor->gettempDocumentMainPart(); $innerXml = preg_replace('/^[\s\S]*<w:body>(.*)<\/w:body>.*/', '$1', $innerXml); // remove tag containing header, footer, images $innerXml = preg_replace('/<w:sectPr>.*<\/w:sectPr>/', '', $innerXml); // inject internal xml inside main template $mainXml = $mainTemplateProcessor->gettempDocumentMainPart(...

Connecting to MySQL 8 from Old PHP version using mysqli

If you have upgraded your MySQL to MySQL 8 version and still using older version of PHP you might encounter a few problems in the connection using mysqli connector library. 1. The first problem we are going to solve is: php mysql 8: "Server sent charset (255) unknown to the client. Please, report to the developers" The problem is that MySQL have changed the default character set from utf8 to utf8mb4 and it is not supported by mysqli connector (nor PDO as I have checked) in older versions of php. "The default collation for utf8mb4 differs between MySQL 5.7 and 8.0 ( utf8mb4_general_ci for 5.7, utf8mb4_0900_ai_ci for 8.0). When the 8.0 client requests a character set of utf8mb4 , what it sends to the server is the default 8.0 utf8mb4 collation; that is, the utf8mb4_0900_ai_ci." https://dev.mysql.com/doc/refman/8.0/en/charset-connection.html The way to solve it easily (there are other ways, such as upgrading php or connectors and more ...) is to force MySQL 8.0 to ...

האפשרות ש - Microsoft Excel יוכל לקרוא קובץ CSV ב - UTF-8

עבודה עם אקסל יכולה להיות מאוד מרגיזה לפעמים. לצערנו Excel עדיין עובד בברירת המחדל ב - Windows-1255 Encoding. אבל מה אם אנחנו רוצים ליצור קובץ CSV מתקדם יותר ... נניח UTF8. הפתרון נמצא ב - BOM :  header("Content-Type: text/csv; charset=UTF-8");  header("Content-Disposition: attachment; filename=$filename"); // Disable caching  header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1  header("Pragma: no-cache"); // HTTP 1.0  header("Expires: 0"); // Proxies  $out = fopen('php://output', 'w');  $BOM = "\xEF\xBB\xBF"; // UTF-8 BOM  fwrite($out, $BOM);  $headlines = array("a", "b", "c");  fputcsv($out, $headlines);  // loop data here  fclose($out);

PHP: Converting __toString when calling json_encode using JsonSerializable interface

JsonSerializable   { /* Methods */ abstract   public   mixed   jsonSerialize   (   void   ) } When calling a json_encode on an object: See: http://stackoverflow.com/questions/401908/php-tostring-and-json-encode-not-playing-well-together And: http://php.net/manual/en/class.jsonserializable.php

הוספת BOM UTF-8 לקבצים ב - PHP

$csv_file  = fopen("barvaz/barvazon.csv", 'w') or die("can't create bar baz"); fwrite($csv_file, "\xEF\xBB\xBF");

הרצת PHP מתוך cron

הרצת PHP מתוך cron 0 7 * * * cd /to/the/directory && php -f /to/the/directory/code.php >> /file.log 2>&1 יש לזכור לבצע cd  לספריה שבה יושב הקוד אחרת הוא יורץ מתוך ספריית הבית של ה - user הוספת  2>&1 בסוף השורה גורמת להודעות שגיאה שה - php מוציא להכנס ללוג stdout שאנחנו מיצרים בעזרת >>

PHP וחילוץ נתונים מתוך HTML

במקרים רבים (ואנשים רבים שואלים אותי) אנחנו צריכים לחלץ נתונים מאתרי אינטרנט ודפי HTML. מהי הדרך הטובה ביותר לעשות זאת? ומהי הדרך הנוחה ביותר לעשות זאת? כמובן שאם האתר מספק לנו נתונים באמצעות XML או באופן מדוייק יותר RSS הפתרון הוא קל יחסית, ושימוש ביכולות המובנות של PHP לניתוח XML/RSS באות לעזרתנו. לדוגמא, simple_xml_loadfile . אך מה קורה אם אין אפשרות לגשת לאתר לקבלת מידע בפורמטים מקובלים כמו XML/RSS או JSON, ואנו נאלצים לפרסס (Parsing)\ לנתח את הדף בעצמנו? לכך מצאתי כמה פתרונות נחמדים: הראשון, הפשוט יותרת שימוש בפונקציה אשר מחלצת נתונים המופיעים בין שתי מחרוזות (strings). השני המתוחכם יותרת והנוח יותר הוא שימוש בספריית php המיצרת לנו DOM בתוך ה - PHP ומאפשרת לבצע שאילתות DOM וכן Selectors מתוך קוד ה - php על דף ה - HTML אותו אנו מנסים לפענח. לפתרון הראשון: // $text - is the full text we are searching on // $from - is the opening text we start taking data from // $to - is array of optional ending text we will fetch text until // text_between('this is a full text', 'is...

החלפה בין שני משתנים ב - PHP

לעיתים יש לנו שני ערכים בשני משתנים שונים שאנחנו רוצים להחליף ביניהם. $a = 5; $b = 7; כמובן שאפשר להחליף ערכים באמצעות משתנה שלישי: $x = $a; $a = $b; $b = $x; אבל זו לא חוכמה כל כך גדולה ... אפשר גם להחליף ערכים בצורה כזו, קצת יותר מתחוכמת ועושה שימוש בפונקציה list : list($a, $b) = array($b, $a); אבל זה לא יעבוד עם מערכים, ולכן מצאתי שיטה נוספת להחלפת משתנים $x ^= $y ^= $x ^= $y; חמוד לא?