# thara

Members

540

## Community Reputation

5 Neutral

• Rank
Prolific Member
• Birthday 02/05/1983

• Gender
Male
• Location
Panda

## Contact Methods

• Skype
tharangagamage

## Recent Profile Visitors

10,795 profile views

1. ## PHP function to convert Hex to HSL (Not HSL to Hex)

I am trying to convert colors from Hex to HSL (Not HSL to Hex). I am using a PHP function for this purpose. But It's not working properly for some colors. For example for #e04c4c the HSL should be (0, 70%, 59%) which it isn't the case with the function. function hexToHsl(\$hex) { \$red = hexdec(substr(\$hex, 0, 2)) / 255; \$green = hexdec(substr(\$hex, 2, 2)) / 255; \$blue = hexdec(substr(\$hex, 4, 2)) / 255; \$cmin = min(\$red, \$green, \$blue); \$cmax = max(\$red, \$green, \$blue); \$delta = \$cmax - \$cmin; if (\$delta === 0) { \$hue = 0; } elseif (\$cmax === \$red) { \$hue = ((\$green - \$blue) / \$delta) % 6; } elseif (\$cmax === \$green) { \$hue = (\$blue - \$red) / \$delta + 2; } else { \$hue = (\$red - \$green) / \$delta + 4; } \$hue = round(\$hue * 60); if (\$hue < 0) { \$hue += 360; } \$lightness = ((\$cmax + \$cmin) / 2) * 100; \$saturation = \$delta === 0 ? 0 : (\$delta / (1 - abs(2 * \$lightness - 1))) * 100; if (\$saturation < 0) { \$saturation += 100; } \$lightness = round(\$lightness); \$saturation = round(\$saturation); //return "hsl(\${hue}, \${saturation}%, \${lightness}%)"; return array(\$hue, \$saturation, \$lightness); } This is how I used it: \$templatePrimaryColor = '#e04c4c'; \$templatePrimaryColor = str_replace("#", "",\$templatePrimaryColor); list(\$h,\$s,\$l) = hexToHsl(\$templatePrimaryColor); \$primaryColor = "hsl(\${h}, \${s}%, \${l}%)"; This is the output: echo '<pre>',print_r(hexToHsl(\$templatePrimaryColor)).'</pre>'; Array ( [0] => 0 [1] => 99 [2] => 59 ) 1 Does anyone know what is the problem there? Thank you.
2. ## How to combine LESS color functions and CSS Variables

In my project I have a CSS custom variables like this: :root { --primary-color: #e04c4c; --secondary-color: #2c2c5e; --text-color: #d67900; } In my LESS files I have used LESS color functions to get more colors base on its primary and secondary. This is how its look like: .component1 { background: darken(--primary-color, 10%); } .component2 { background: lighten(--secondary-color, 5%); } But when I compile this, it gives an error like this? When googling I found a solution for SASS, but not for LESS. Can anybody tell me is there any possible workaround for this particular case? Thank you.
3. ## How to check only alphanumeric and other language alphabet by using preg_replace?

Thanks for reply. Yes I tried it like that. Updated version: function seoUrl(\$string) { //Lower case everything \$string = strtolower(\$string); //Make alphanumeric (removes all other characters) \$string = preg_replace("/[^\pL\pN_\s-]/u", "", \$string); //Clean up multiple dashes or whitespaces \$string = preg_replace("/[\s-]+/", " ", \$string); //Convert whitespaces and underscore to dash \$string = preg_replace("/[\s_]/", "-", \$string); return \$string; } \$title = seoUrl("this-is-a-දහසක්-බාධක-දුක්-කම්කටොලු-මැදින්-ලෝකය-දිනන්නට-වෙර-දරන"); echo \$title; Output: this-is-a-දහසක-බධක-දක-කමකටල-මදන-ලකය-දනනනට-වර-දරන But some parts are missing in sinhala characters. Please look at two string closely, you will notice the difference.
4. ## How to check only alphanumeric and other language alphabet by using preg_replace?

I need to create a SEO friendly string only from alphanumeric and characters of my native language. It is sinhala. My expected string should be something like this: \$myString = "this-is-a-දහසක්-බාධක-දුක්-කම්කටොලු-මැදින්-ලෝකය-දිනන්නට-වෙර-දරන"; I am using a function to create the string like this. And that function is as follow: function seoUrl(\$string) { //Lower case everything \$string = strtolower(\$string); //Make alphanumeric (removes all other characters) \$string = preg_replace("/[^a-z0-9_\s-]/", "", \$string); //Clean up multiple dashes or whitespaces \$string = preg_replace("/[\s-]+/", " ", \$string); //Convert whitespaces and underscore to dash \$string = preg_replace("/[\s_]/", "-", \$string); return \$string; } This function only works for English characters and output of above string as below: \$title = seoUrl("this-is-a-දහසක්-බාධක-දුක්-කම්කටොලු-මැදින්-ලෝකය-දිනන්නට-වෙර-දරන"); echo \$title; // this-is-a- I modified this function using `mb_ereg_replace` as below: function seoUrl(\$string) { //Lower case everything //\$string = strtolower(\$string); //Make alphanumeric (removes all other characters) \$string = mb_ereg_replace("/[^a-z0-9_\s-]/", "", \$string); //Clean up multiple dashes or whitespaces \$string = mb_ereg_replace("/[\s-]+/", " ", \$string); //Convert whitespaces and underscore to dash \$string = mb_ereg_replace("/[\s_]/", "-", \$string); return \$string; } But is not working for me. Can anybody tell me how to modify above function to get all my characters (including my native language characters) Hope somebody may help me out. Thank you.
5. ## Remove related element from multidimensional array

Sir, I tried it in this way: //Insert other post image: if(!empty(\$_SESSION['other-image'])) { \$record_vals = []; foreach (\$other_image as \$name => \$values) { foreach (\$values as \$k => \$v) { \$record_vals[\$k][\$name] = \$v; } } \$query = "INSERT INTO post_image ( image_type , image , thumb , image_path , sort_order , added_date ) VALUES (?,?,?,?,?,NOW())"; \$stmt = \$mysqli->prepare(\$query); \$stmt->bind_param('isssi', \$type , \$image , \$thumb , \$path , \$sort_order ); \$order=2; foreach (\$record_vals as \$k = > \$v) { foreach (\$v as \$column => \$value) { \$image = \$record_vals[\$k]['img'][\$value]; \$path = \$record_vals[\$k]['path'][\$value]; \$type = \$record_vals[\$k]['type'][\$value]; \$thumb = \$record_vals[\$k]['thumb'][\$value]; \$sort_order = \$order; \$stmt->execute(); } ++\$order; } } Can you tell me what is the mistake I have done?
6. ## Remove related element from multidimensional array

Yes sir. Its exactly what I needed. Now I want to insert these data into mysql. Sir, can you tell me how to do it? I tried it something like this, but it doesn't work. //Insert other post image: if(!empty(\$_SESSION['other-image'])) { \$query = "INSERT INTO post_image ( image_type , image , thumb , image_path , sort_order , added_date ) VALUES (?,?,?,?,?,NOW())"; \$stmt = \$mysqli->prepare(\$query); \$stmt->bind_param('isssi', \$type , \$image , \$thumb , \$path , \$sort_order ); \$order=2; foreach (\$_SESSION['other-image'] as \$value) { foreach (\$value as \$v) { \$type = \$_SESSION['other-image']['type'][\$v]) \$image = \$_SESSION['other-image']['img'][\$v]) \$thumb = \$_SESSION['other-image']['thumb'][\$v]) \$path = \$_SESSION['other-image']['path'][\$v]) \$sort_order = \$order; \$stmt->execute(); } ++\$order; } }
7. ## Remove related element from multidimensional array

This is my array. It has stored images data. [other-image] => Array ( [img] => Array ( [0] => 1526973657.jpg [1] => 1526973661.jpg [2] => 1526973665.jpg ) [path] => Array ( [0] => ../post-upload/1/ [1] => ../post-upload/1/ [2] => ../post-upload/1/ ) [type] => Array ( [0] => 1 [1] => 1 [2] => 1 ) [thumb] => Array ( [0] => thumb_1526973661.jpg [1] => thumb_1526973665.jpg [2] => thumb_1526973668.jpg ) ) Now I want to delete an image and it's all related data from sub arrays. (path, type, thumb data) This is how I tried it in php: \$delkey = \$_POST['key']; if(in_array(\$delkey, \$_SESSION['other-image']['img'])){ \$imgkey = array_search(\$delkey, \$_SESSION['other-image']['img']); if(\$imgkey) unset(\$_SESSION['other-image']['img'][\$imgkey]); //file path \$fp = UPLOAD_DIR.\$nextId."/".\$delkey; unlink(\$fp); } As I did, its only deleting element form 'img' array, but I want to delete related data from other arrays too. Can anybody tell me how to do this? Thank you.
8. ## Mysql insert issue with chracters from my native language

mysql> SHOW VARIABLES LIKE '%char%'; +--------------------------+------------------------------------------------+ | Variable_name | Value | +--------------------------+------------------------------------------------+ | character_set_client | cp850 | | character_set_connection | cp850 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | cp850 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | I:\wamp64\bin\mysql\mysql5.7.9\share\charsets\ | +--------------------------+------------------------------------------------+ 8 rows in set (1.15 sec) This is how I connect to PHP: \$mysqli = new MySQLi(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Verify the connection and // Set the character set: if (\$mysqli->connect_error) { //echo \$mysqli->connect_error; //unset(\$mysqli); echo 'Database connection failed...' . 'Error: ' . \$mysqli->connect_errno . ' ' . \$mysqli->connect_error; exit(); } else { // Establish the encoding. \$mysqli->set_charset('utf8'); } Insert is ok with PHP. but problem is, when using command line interface.
9. ## Mysql insert issue with chracters from my native language

I am trying to insert data from my mother language (Sinhala) into my mysql table. But MySQL displays my chracters as question marks. This is how I test it: CREATE DATABASE sinhala_test; USE kindheart; ALTER DATABASE sinhala_test CHARACTER SET utf8 COLLATE utf8_general_ci CREATE TABLE IF NOT EXISTS `category` ( `category_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name_si` VARCHAR(100) COLLATE utf8_unicode_ci NOT NULL, `description_si` TEXT COLLATE utf8_unicode_ci NOT NULL, `last_update` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`category_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; INSERT INTO `category` VALUES (1,'පොත් පත් සහ පාසල් උපකරණ','නවතම පොත් පත් අවශ්‍යතා ඇතුළු සියළුම පාසැල් හා අධ්‍යාපන මෙවලම්.',NOW()); This is what can I get from MySQL command line: mysql> select * from category\G *************************** 1. row *************************** category_id: 1 name_si: ???? ??? ?? ????? ????? description_si: ???? ??????? ??????? ????????. ????/????????? ????? ?????? ?????? ?? ???????? ??????. last_update: 2018-05-20 11:11:20 Can anybody tell me how can I fix this problem? NOTE: When inserting from phpMyAdmin its correctly work.
10. ## Owl carousel issue inside bootstrap tab

I'm trying to add owl carousel for each bootstrap tab. Carousel in the first tab is loading perfectly, but when user clicks on second tab, owl carousel items are not loading. That mean on second tab it displays empty space instead of displaying carousel items. My HTML is something like this: <!-- Nav tabs --> <ul class="nav nav-tabs" role="tablist"> <li role="presentation" class="active"><a href="#female" aria-controls="female" role="tab" data-toggle="tab">Female</a></li> <li role="presentation"><a href="#male" aria-controls="male" role="tab" data-toggle="tab">Male</a></li> </ul> <!-- Tab panes --> <div class="tab-content"> <div role="tabpanel" class="tab-pane active" id="female"> <div data-items="1" data-lg-items="7" data-margin="20" class="owl-carousel" data-autoplay='false'> <div> <a href="#"> <div> <img src="images/profile/profile1.jpg" alt="" class="img-responsive center-block"> </div> </a> </div> <div> <a href="#"> <div> <img src="images/profile/profile2.jpg" alt="" class="img-responsive center-block"> </div> </a> </div> <div> <a href="#"> <div> <img src="images/profile/profile3.jpg" alt="" class="img-responsive center-block"> </div> </a> </div> </div> </div> <div role="tabpanel" class="tab-pane" id="male"> <div data-items="1" data-lg-items="7" data-margin="20" class="owl-carousel" data-autoplay='false'> <div> <a href="#"> <div> <img src="images/profile/profile1.jpg" alt="" class="img-responsive center-block"> </div> </a> </div> <div> <a href="#"> <div> <img src="images/profile/profile2.jpg" alt="" class="img-responsive center-block"> </div> </a> </div> <div> <a href="#"> <div> <img src="images/profile/profile3.jpg" alt="" class="img-responsive center-block"> </div> </a> </div> </div> </div> </div> This is my JS looks like: var plugins = { bootstrapTabs: \$(".tabs"), owl: \$(".owl-carousel") }; if (plugins.owl.length) { var i; for (i = 0; i < plugins.owl.length; i++) { var c = \$(plugins.owl[i]), responsive = {}; var aliaces = ["-", "-xs-", "-sm-", "-md-", "-lg-"], values = [0, 480, 768, 992, 1200], j, k; for (j = 0; j < values.length; j++) { responsive[values[j]] = {}; for (k = j; k >= -1; k--) { if (!responsive[values[j]]["items"] && c.attr("data" + aliaces[k] + "items")) { responsive[values[j]]["items"] = k < 0 ? 1 : parseInt(c.attr("data" + aliaces[k] + "items")); } if (!responsive[values[j]]["stagePadding"] && responsive[values[j]]["stagePadding"] !== 0 && c.attr("data" + aliaces[k] + "stage-padding")) { responsive[values[j]]["stagePadding"] = k < 0 ? 0 : parseInt(c.attr("data" + aliaces[k] + "stage-padding")); } if (!responsive[values[j]]["margin"] && responsive[values[j]]["margin"] !== 0 && c.attr("data" + aliaces[k] + "margin")) { responsive[values[j]]["margin"] = k < 0 ? 30 : parseInt(c.attr("data" + aliaces[k] + "margin")); } } } c.owlCarousel({ autoplay: c.attr("data-autoplay") === "true", loop: c.attr("data-loop") !== "false", items: 1, dotsContainer: c.attr("data-pagination-class") || false, navContainer: c.attr("data-navigation-class") || false, mouseDrag: "false", nav: c.attr("data-nav") === "true", dots: c.attr("data-dots") === "true", dotsEach: c.attr("data-dots-each") ? parseInt(c.attr("data-dots-each")) : false, animateIn: c.attr('data-animation-in') ? c.attr('data-animation-in') : 'fadeIn', animateOut: c.attr('data-animation-out') ? c.attr('data-animation-out') : 'fadeOut', responsive: responsive, navText: [] }); } \$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { e.target // newly activated tab e.relatedTarget // previous active tab \$(".owl-carousel").trigger('refresh.owl-carousel'); }); } So can anybody tell me how to fix this issue? Hope somebody may help me out. Thank you.
11. ## Hiya everyone

Welcome to PHPFreaks!
12. ## Hello Everyone

Welcome to PHPFreaks!
13. ## Congratulations to Barand on 1000 likes

I too love Barand, I know, my contributions is over 100 likes for him. Congratulations Sir!!! Anyway anybody have a looked at this profile?
14. ## Making directories with recursive function

Basically I am having an array something like below, this array has number of categories and sub, sub sub categories. \$categories = array( array('id' => 1, 'parent' => 0, 'name' => 'Category'), array('id' => 2, 'parent' => 1, 'name' => 'Category A'), array('id' => 3, 'parent' => 1, 'name' => 'Category B'), array('id' => 4, 'parent' => 1, 'name' => 'Category C'), array('id' => 5, 'parent' => 1, 'name' => 'Category D'), array('id' => 6, 'parent' => 1, 'name' => 'Category E'), array('id' => 7, 'parent' => 2, 'name' => 'Subcategory F'), array('id' => 8, 'parent' => 2, 'name' => 'Subcategory G'), array('id' => 9, 'parent' => 3, 'name' => 'Subcategory H'), array('id' => 10, 'parent' => 4, 'name' => 'Subcategory I'), array('id' => 11, 'parent' => 9, 'name' => 'Subcategory J'), ); Using this array I have created a nested <ul>. This is the recursive function I have used for : foreach (\$categories as \$category) { \$id = \$category['id']; \$parent = \$category['parent']; \$name = \$category['name']; //echo \$name."<br>"; \$cats[\$parent][\$id] = \$name; } function displayList(&\$cats, \$parent, \$current=0, \$level=0) { switch (\$level) { case 0: \$class = "level_1 has_sub no_active"; \$a_class = "c1"; break; case 1: \$class = "level_2 has_sub no_active"; \$a_class = "c2"; break; case 2: \$class = "level_3 has_sub no_active"; \$a_class = "c3"; break; } if (\$parent==0) { foreach (\$cats[\$parent] as \$id=>\$nm) { if (isset(\$cats[\$id])) { displayList(\$cats, \$id, \$current); } } } else { echo "<ul class='\$class'>\n"; foreach (\$cats[\$parent] as \$id=>\$nm) { \$clear = preg_replace('/[^a-zA-Z0-9\s]/', '', strip_tags(html_entity_decode(\$nm))); \$pageName = strtolower(str_replace(' ', '-', \$clear)); \$link = \$pageName.'.php'; echo "<li><a href='\$link' class='\$a_class \$sel'><span>\$nm</span></a>\n"; if (isset(\$cats[\$id])) { displayList(\$cats, \$id, \$current, \$level+1); } echo '</li>'; } echo "</ul>\n"; } } Look at that function, I have created a link for each category. Category name itself has used as page name. (Removing by special chars.) My question is, when this function executing I want to create folders for level one categories. Those category names should be used as folder names. Example from above array: category_a category_b category_c category_d category_e So, every sub category pages should be inside these parent category folders. Can I know is this possible in this function? Thank you.
15. ## Myphpadmin - DD MM YYYY ?

It doesn't matter. You can retrieve dates in whatever format you want Eg: SELECT DATE_FORMAT('2017-01-23', '%d/%m/%Y') But, you must however save all dates using the YYYY-MM-DD format as that is the only format that mysql date fields can accept (it is also the only format where you can sort into date order)..
×

• #### Activity

• Chat
×
• Create New...