Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,150,624 members, 7,809,308 topics. Date: Friday, 26 April 2024 at 07:38 AM |
Nairaland Forum / Science/Technology / Programming / Please Help With Php Script (1121 Views)
Sorting Out A Simple Text Dictionary With PHP / Can Obfuscated Php Script Be Decoded? (2) (3) (4)
Please Help With Php Script by anonymoux: 12:38am On Sep 16, 2014 |
Please guys, I am working on my site. But have this little problem with my php script. I need to check if string have less than 4 characters. $str = "33322222EEEEE"; if(!preg_match(??, $str)) { msg = str." has less than 4 numbers/characters" } |
Re: Please Help With Php Script by GodMode: 4:00am On Sep 16, 2014 |
anonymoux: Please guys, I am working on my site. you can use the strlen() or mb_strlen() function but there are other functions. change your if statement to: echo strlen($str); pls read the php manual for your sake. |
Re: Please Help With Php Script by adexsimply(m): 5:21am On Sep 16, 2014 |
<?php |
Re: Please Help With Php Script by anonymoux: 10:52am On Sep 16, 2014 |
@adexsimply & @GodMode Thank you guyz so much, but you dont seems to get my problem. I cant use strlen because it count the overall number or characters. I need a code than can be like: if I enter: 11111 = it will say: only one character was entered(because I enter 1 five times. so it will disregard all the other extra times 1 was entered) and if I enter 111122223333 = it will say: it will tell me only 3 characters are entered. (Because I enter 1, 2 and 3 repeated it, it wont cant repetitions). Thank you! |
Re: Please Help With Php Script by adexsimply(m): 12:34pm On Sep 16, 2014 |
anonymoux: @adexsimply & @GodMode <?php NOTE:count_chars accept 2 parameters, the second parameter is known as "mode". In this case, I used "mode 3" which will return a string with all the different characters used. I then counted the characters using the more familiar "strlen" Capisce? |
Re: Please Help With Php Script by anonymoux: 1:16pm On Sep 16, 2014 |
<?php $a = 'apple'; $b = 'ball'; $duplicates = array_count_values(array_merge(str_split($a), str_split($b))); // Array ( [a] => 2 [p] => 2 [l] => 3 [e] => 1 [b] => 1 ) print_r($duplicates); $totalMatches = 0; foreach($duplicates as $count) { if($count > 1) $totalMatches += $count; } // 7 matches! echo $totalMatches . ' matches!'; ?> I have gotten what I needed. Easy and Perfect!!! |
Re: Please Help With Php Script by adexsimply(m): 1:25pm On Sep 16, 2014 |
Sorry, can you explain? anonymoux: <?php |
Re: Please Help With Php Script by anonymoux: 2:03pm On Sep 16, 2014 |
<?php Above is a more understandable version of what I actually wanted. in this above example. $totalMaches will come out as: [b] Array ( [a] => 2 [p] => 2 [l] => 3 [e] => 1 [b] => 1 ) which means letter a appears twice letter p appears twice letter l appears thrice and so on.... counting duplicates and even non duplicates... |
Re: Please Help With Php Script by GodMode: 2:42pm On Sep 16, 2014 |
anonymoux: that's not what you explained OOOoooo. but this is similar to what you explained <?php $data = '1111222233333444455555'; $work = array_unique(str_split($data)); echo count($work); ?> |
Re: Please Help With Php Script by adexsimply(m): 5:03pm On Sep 16, 2014 |
anonymoux:Okay..But, <?php |
Re: Please Help With Php Script by GodMode: 7:44pm On Sep 16, 2014 |
adexsimply: U copied that code from the manual... www.php.net/manual/en/function.count-chars.php |
Re: Please Help With Php Script by anonymoux: 12:15pm On Sep 17, 2014 |
thanks adexsimply: |
Re: Please Help With Php Script by Nobody: 1:55pm On Sep 17, 2014 |
PHP can be ugly sometimes. |
(1) (Reply)
After The Basic Of Python / Suggest A Short Code Service Operator For My APP / Help: Please, Recommend A Tool/platform To Build A Social Network Portal
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 23 |