This question already has answers here:
Php length of cyrillic string doubles its value
(3 answers)
Closed 7 years ago.
I'm doing application for string length check. When checking Cyrillic string there shows wrong because of the unicode. How to solve this problem?
$str=strlen ('abc');
echo $str; // result is 3
$str=strlen ('АБС');
echo $str; // result is 6. How to find correct value
Was little curious about this question.
First options is as suggested by Rizier123(no doubt, that works perfectly.)
Second:
You can also use utf8_decode() to get the result.
<?php
$str=strlen (utf8_decode('АБС'));
echo $str;
?>
Check demo here
Related
This question already has answers here:
How do I convert a string to a number in PHP?
(35 answers)
Closed 2 years ago.
I have a value like 12,25,246
I want to get 1225246 (must be an integer)
How can I do that?
I have searched a lot but there are direct answer like converting string to integer but not like this actually these both are like integer
I have tried php formate_number but it did not worked.
You could use a combination of intval() and str_replace() to do this.
Example:
$value = '12,25,246';
var_dump(intval(str_replace(',','',$value)));
// Yields: "int(1225246)"
Sandbox
$number = (int)str_replace(',', '', '12,25,246');
here is it
This question already has answers here:
PHP - Plus sign with GET query
(6 answers)
When should space be encoded to plus (+) or %20? [duplicate]
(5 answers)
Closed 3 years ago.
First of all thanks in advance to everyone helping me out with my question.
I've got a base64_encoded string that looks like:
$_GET['val']='8AH1Oc+gqwjMPyyAL+PIu2neFF5C+bQAkDf/FJdApT4AC09jD/o9I3vHs0cIPC8678TzuFMVlZd+7zA/fV1b9OEF0Uwnao3aURtGUkbx4NoEQFvQ1hBPy0EbUobbRQO/WojW9F6oowS/yX+I+qj53N4nORxhKJRDzMIQO1W8sOSH1BkBHsCotG1dj813OWLoBLy+K9ABLBqUta9+0Mk3JCg+wO/WA2Bh06M0n4ux+qk=';
but when im trying to get the same variable to decode it i recieve it with pluses removed:
$string=$_GET['val'];
echo $string; // either echo $_GET['val']; output will be '8AH1Oc gqwjMPyyAL PIu2neFF5C bQAkDf/FJdApT4AC09jD/o9I3vHs0cIPC8678TzuFMVlZd 7zA/fV1b9OEF0Uwnao3aURtGUkbx4NoEQFvQ1hBPy0EbUobbRQO/WojW9F6oowS/yX I qj53N4nORxhKJRDzMIQO1W8sOSH1BkBHsCotG1dj813OWLoBLy K9ABLBqUta9 0Mk3JCg wO/WA2Bh06M0n4ux qk='
Could somebody please explain why does it happen?
This question already has answers here:
Limiting the output of PHP's echo to 200 characters
(15 answers)
Closed 3 years ago.
I'm beginner and I have a question. I would like that if my text is more than 5 characters, that it writes 5 characters + ... . It's for shortening a name in navbar if its too long, it causes bugs in my nav.
Here's an example of desired result:
My text: TheTest
output: TheTe...
I think I could do this with strlen() but have no idea how to do this. Maybe with an overflow ?
I tried to do it with text-overflow: ellipsis; but it didn't work either
Can you help me please ?
just check the length to see if its more than 5 character or not
$mesage="This is text String";
if(strlen($mesage)>5){
echo substr($mesage,0,5)."...";
}
else{
echo $mesage;
}
More infos about strlen(): http://www.php.net/manual/de/function.strlen.php
substr(): https://www.php.net/manual/en/function.substr.php
This question already has answers here:
php trim(), work poorly
(2 answers)
Closed 9 years ago.
$individual_file["uri"] = "public://iStock_000000527255XSmall.jpg";
print_r(ltrim($individual_file["uri"], "public://"));
Result -: Stock_000000527255XSmall.jpg
Why the missing i? But when my character starts with si, I get si in the result. Why does trim behave differently?
$individual_file["uri"] = "public://siStock_000000527255XSmall.jpg";
print_r(ltrim($individual_file["uri"], "public://"));
Result -: siStock_000000527255XSmall.jpg
It's because charlist is literally a list of single characters to remove from the left side of the string and i is listed in public://. Any character that falls in this list will be removed, no matter the order.
Ref: http://php.net/manual/en/function.ltrim.php
In fact this:
$individual_file["uri"] = "public://iStock_000000527255XSmall.jpg";
print_r(ltrim($individual_file["uri"], "publc://"));
would output:
ic://iStock_000000527255XSmall.jpg
Another example by changing the order:
$individual_file["uri"] = "public://iStock_000000527255XSmall.jpg";
print_r(ltrim($individual_file["uri"], "bcilpu:/"));
would output:
Stock_000000527255XSmall.jpg
This question already has answers here:
How do I count comma-separated values in PHP?
(5 answers)
Closed 9 years ago.
$string = "oidjdssd , odi,jdois, 3089u,, oisdjsd";
How do i find out if theres more than 3 commas in the string above in the best way?
I would suggest substr_count. You can see if the result is >3 to see if there's more than three.
echo count_chars($string)[ord(',')];
Or for PHP<5.4
$chars = count_chars($string);
echo $chars[ord(',')];
BTW: As it seems, that you are handling CSV-data, you should have a look at str_getcsv()